ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213863 | #2406. Thief Masters | STASISZHY | 100 | 787ms | 32264kb | C++11 | 3.3kb | 2024-11-13 22:40:04 | 2024-11-13 23:10:53 |
answer
// Problem: C. Thief Masters
// Contest: undefined - NOIP2024训练赛 04
// URL: http://www.noi.ac/contest/1156/problem/2406
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
// #define int long long
// #define x first
// #define y second
#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)
inline void debug() { cerr << '\n'; }
template<typename Type, typename... Other>
inline void debug(const Type& x, const Other&... y) { cerr << x << ' '; debug(y...); }
#define DEBUG(a...) cerr << "[" << #a << "] = ", debug(a);
typedef long long LL;
typedef pair<int, int> PII;
const int N = 2010;
const int INF = 0x3f3f3f3f;
template<typename Type>
inline void read(Type &res)
{
res = 0;
int ch = getchar(), flag = 0;
while (!isdigit(ch)) flag |= ch == '-', ch = getchar();
while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
res = flag ? -res : res;
}
template<typename Type, typename... Other>
inline void read(Type &res, Other&... y) { read(res), read(y...); }
int n, m, r, c;
int a[N][N], f[N][N], f2[N][N], ans[N][N];
// f[i][j] = \max { f[i][j], f[i + 1][j] ... f[i + r - 1][j] }
// ans[i][j] = \max { ans[i][j], ans[i][j + 1], ans[i][j + 2] ... ans[i][j + r - 1]; }
int que[N], hh = 0, tt = -1;
int que2[N], hh2 = 0, tt2 = -1;
signed main()
{
read(n, m, r);
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= m; j ++) read(a[i][j]);
for (int j = 1; j <= m; j ++)
{
hh = 0, tt = -1;
for (int i = 1; i <= n; i ++)
{
while (hh <= tt && i - que[hh] >= r) hh ++;
while (hh <= tt && a[que[tt]][j] <= a[i][j]) tt --;
que[++ tt] = i;
if (i >= r) f[i - r + 1][j] = a[que[hh]][j];
}
}
for (int j = 1; j <= m; j ++)
{
hh2 = 0, tt2 = -1;
for (int i = 1; i <= n; i ++)
{
while (hh2 <= tt2 && i - que2[hh2] >= r) hh2 ++;
while (hh2 <= tt2 && a[que2[tt2]][j] >= a[i][j]) tt2 --;
que2[++ tt2] = i;
if (i >= r) f2[i - r + 1][j] = a[que2[hh2]][j];
}
}
for (int i = 1; i <= n; i ++)
{
hh = 0, tt = -1;
for (int j = 1; j <= m; j ++)
{
while (hh <= tt && j - que[hh] >= r) hh ++;
while (hh <= tt && f[i][que[tt]] <= f[i][j]) tt --;
que[++ tt] = j;
if (j >= r) ans[i][j - r + 1] = f[i][que[hh]];
}
}
for (int i = 1; i <= n; i ++)
{
hh2 = 0, tt2 = -1;
for (int j = 1; j <= m; j ++)
{
while (hh2 <= tt2 && j - que2[hh2] >= r) hh2 ++;
while (hh2 <= tt2 && f2[i][que2[tt2]] >= f2[i][j]) tt2 --;
que2[++ tt2] = j;
if (j >= r) ans[i][j - r + 1] = abs(ans[i][j - r + 1] - f2[i][que2[hh2]]);
}
}
int res = INF;
for (int i = 1; i <= n - r + 1; i ++)
for (int j = 1; j <= m - r + 1; j ++) res = min(res, ans[i][j]);
// for(int i = 1; i <= n - r + 1; i ++)
// {
// for(int j = 1; j <= m - r + 1; j ++) cout << ans[i][j] << ' ';
// cout << '\n';
// }
cout << res << '\n';
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 133ms
memory: 30692kb
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: 0ms
memory: 1248kb
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: 2ms
memory: 2848kb
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: 106ms
memory: 32264kb
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: 38ms
memory: 12404kb
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: 61ms
memory: 15508kb
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: 91ms
memory: 31080kb
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: 57ms
memory: 11708kb
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: 99ms
memory: 15152kb
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: 200ms
memory: 30688kb
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