ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213793 | #2406. Thief Masters | one_zero_four_zero | 100 | 1673ms | 21204kb | C++11 | 1.9kb | 2024-11-13 19:44:21 | 2024-11-13 23:03:18 |
answer
#include<bits/stdc++.h>
using namespace std;
int A, B, N, t, ans = 0x3f3f3f3f;
vector<int> tmp0[1005], tmp1[1005], tmp2[1005];
vector<int> maxn[1005], minn[1005];
void putout(vector<int> a, string tmp = " "){
for (auto && i : a){
cout << i << tmp;
}
cout << "\n";
}
vector<int> calcMAX(vector<int> a){
int l = 0;
vector<int> q, res;
for (int i = 0; i < (int)a.size(); i ++){
while (l < (int)q.size() && i - q[l] + 1 > N) l ++;
while (l < (int)q.size() && a[q.back()] < a[i]) q.pop_back();
q.push_back(i);
if (i >= N - 1) res.push_back(a[q[l]]);
}
return res;
}
vector<int> calcMIN(vector<int> a){
int l = 0;
vector<int> q, res;
for (int i = 0; i < (int)a.size(); i ++){
while (l < (int)q.size() && i - q[l] + 1 > N) l ++;
while (l < (int)q.size() && a[q.back()] > a[i]) q.pop_back();
q.push_back(i);
if (i >= N - 1) res.push_back(a[q[l]]);
}
return res;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("../data.in", "r", stdin);
freopen("../data.out", "w", stdout);
#endif
scanf("%d %d %d", &A, &B, &N);
for (int i = 0; i < A; i ++){
for (int j = 0; j < B; j ++){
scanf("%d", &t);
tmp0[i].push_back(t);
}
}
for (int i = 0; i < A; i ++){
vector<int> tmp = calcMAX(tmp0[i]);
for (int j = 0; j < B - N + 1; j ++){
tmp1[j].push_back(tmp[j]);
}
tmp = calcMIN(tmp0[i]);
for (int j = 0; j < B - N + 1; j ++){
tmp2[j].push_back(tmp[j]);
}
}
for (int i = 0; i < B - N + 1; i ++){
vector<int> tmp = calcMAX(tmp1[i]);
for (int j = 0; j < A - N + 1; j ++){
maxn[j].push_back(tmp[j]);
}
tmp = calcMIN(tmp2[i]);
for (int j = 0; j < A - N + 1; j ++){
minn[j].push_back(tmp[j]);
}
}
for (int i = 0; i < A - N + 1; i ++){
for (int j = 0; j < B - N + 1; j ++){
// printf("%d::%d ", maxn[i][j], minn[i][j]);
ans = min(ans, maxn[i][j] - minn[i][j]);
}
// printf("\n");
}
printf("%d\n", ans);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 379ms
memory: 19916kb
input:
1000 1000 100 804544523 340648618 718292412 235345736 704741136 942776831 741228920 463473302 677289...
output:
998893495
result:
ok single line: '998893495'
Test #2:
score: 10
Accepted
time: 1ms
memory: 1364kb
input:
5 4 2 1 2 5 6 0 17 16 0 16 17 0 1 2 10 2 1 1 2 3 2
output:
2
result:
ok single line: '2'
Test #3:
score: 10
Accepted
time: 5ms
memory: 1576kb
input:
100 100 10 2 100001 200001 300001 400001 500001 600001 700001 800001 900001 1000001 1100001 1200001 ...
output:
908999
result:
ok single line: '908999'
Test #4:
score: 10
Accepted
time: 375ms
memory: 21204kb
input:
1000 1000 20 1 100001 200001 300001 400001 500001 600001 700001 800001 900001 1000001 1100001 120000...
output:
1901899
result:
ok single line: '1901899'
Test #5:
score: 10
Accepted
time: 85ms
memory: 6020kb
input:
500 500 50 79289095 232165705 955620938 481434262 465576217 112035388 50089892 459799006 181906335 3...
output:
995944328
result:
ok single line: '995944328'
Test #6:
score: 10
Accepted
time: 171ms
memory: 10484kb
input:
500 1000 80 499163842 331022295 940054497 684192083 248823911 842132608 629298697 398526298 98438040...
output:
998299092
result:
ok single line: '998299092'
Test #7:
score: 10
Accepted
time: 321ms
memory: 20236kb
input:
1000 1000 80 102 134 429 251 299 109 264 669 727 296 112 550 270 270 544 660 131 546 968 219 113 678...
output:
998
result:
ok single line: '998'
Test #8:
score: 10
Accepted
time: 38ms
memory: 5608kb
input:
500 500 100 65532583 920409544 753795976 989349545 818384831 778207112 425141881 853270293 542112588...
output:
999172505
result:
ok single line: '999172505'
Test #9:
score: 10
Accepted
time: 91ms
memory: 10248kb
input:
500 1000 100 456896744 779471086 578349238 52507342 192194992 156396237 475084995 775765435 96617474...
output:
998801667
result:
ok single line: '998801667'
Test #10:
score: 10
Accepted
time: 207ms
memory: 19916kb
input:
1000 1000 100 629053044 957239666 456746076 940194386 201529807 592062148 244394389 825620014 223976...
output:
998862873
result:
ok single line: '998862873'
Extra Test:
score: 0
Extra Test Passed