ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#185020 | #2406. Thief Masters | tkswls | 100 | 1304ms | 20976kb | C++11 | 2.0kb | 2023-09-19 09:37:59 | 2023-09-19 12:08:10 |
answer
#include<bits/stdc++.h>
using namespace std;
int n, m, k, a[1005][1005], b[1005], ans, cnt[1005][1005];
struct node {
int num, name;
};
struct ddq {
node b[1005];
int l = 1, r = 0;
inline void update(int p) {
while (l <= r && b[l].name < p) {
l++;
}
}
inline void push(int p, int q) {
while (r >= l && p > b[r].num) {
r--;
}
b[++r] = node{p, q};
}
inline int get_max() {
return b[l].num;
}
inline void init() {
l = 1, r = 0;
}
} q[1005], op;
struct dq {
node b[1005];
int l = 1, r = 0;
inline void update(int p) {
while (l <= r && b[l].name < p) {
l++;
}
}
inline void push(int p, int q) {
while (r >= l && p < b[r].num) {
r--;
}
b[++r] = node{p, q};
}
inline int get_min() {
return b[l].num;
}
inline void init() {
l = 1, r = 0;
}
} p[1005], opp;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> k;
ans = 0x3f3f3f3f;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k - 1; j++) {
q[i].push(a[i][j], j);
p[i].push(a[i][j], j);
}
}
for (int i = k; i <= m; i++) {
for (int j = 1; j <= n; j++) {
q[j].push(a[j][i], i);
q[j].update(i - k + 1);
}
for (int j = 1; j <= n; j++) {
b[j] = q[j].get_max();
}
op.init();
for (int j = 1; j < k; j++) {
op.push(b[j], j);
}
for (int j = k; j <= n; j++) {
op.push(b[j], j);
op.update(j - k + 1);
cnt[j][i] = op.get_max();
}
}
ans = 1000000007;
for (int i = k; i <= m; i++) {
for (int j = 1; j <= n; j++) {
p[j].push(a[j][i], i);
p[j].update(i - k + 1);
}
for (int j = 1; j <= n; j++) {
b[j] = p[j].get_min();
}
opp.init();
for (int j = 1; j < k; j++) {
opp.push(b[j], j);
}
for (int j = k; j <= n; j++) {
opp.push(b[j], j);
opp.update(j - k + 1);
ans = min(ans, cnt[j][i] - opp.get_min());
}
}
cout << ans;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 9344kb
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 #2:
score: 10
Accepted
time: 0ms
memory: 10160kb
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 #3:
score: 10
Accepted
time: 314ms
memory: 20976kb
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 #4:
score: 10
Accepted
time: 33ms
memory: 13188kb
input:
500 500 50 79289095 232165705 955620938 481434262 465576217 112035388 50089892 459799006 181906335 3...
output:
995944328
result:
ok single line: '995944328'
Test #5:
score: 10
Accepted
time: 89ms
memory: 13108kb
input:
500 1000 80 499163842 331022295 940054497 684192083 248823911 842132608 629298697 398526298 98438040...
output:
998299092
result:
ok single line: '998299092'
Test #6:
score: 10
Accepted
time: 184ms
memory: 17208kb
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 #7:
score: 10
Accepted
time: 44ms
memory: 12972kb
input:
500 500 100 65532583 920409544 753795976 989349545 818384831 778207112 425141881 853270293 542112588...
output:
999172505
result:
ok single line: '999172505'
Test #8:
score: 10
Accepted
time: 75ms
memory: 13020kb
input:
500 1000 100 456896744 779471086 578349238 52507342 192194992 156396237 475084995 775765435 96617474...
output:
998801667
result:
ok single line: '998801667'
Test #9:
score: 10
Accepted
time: 311ms
memory: 17100kb
input:
1000 1000 100 629053044 957239666 456746076 940194386 201529807 592062148 244394389 825620014 223976...
output:
998862873
result:
ok single line: '998862873'
Test #10:
score: 10
Accepted
time: 254ms
memory: 17108kb
input:
1000 1000 100 804544523 340648618 718292412 235345736 704741136 942776831 741228920 463473302 677289...
output:
998893495
result:
ok single line: '998893495'
Extra Test:
score: 0
Extra Test Passed