ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213783 | #2406. Thief Masters | jsxheng | 100 | 577ms | 24708kb | C++11 | 1.6kb | 2024-11-13 19:30:56 | 2024-11-13 23:02:15 |
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
namespace IO{
template<typename T> inline void read(T &x){
bool f=1;x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=0;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch&15),ch=getchar();
x=f?x:-x;
}
template<typename T> inline void write(T x){
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(('0'+x%10));
}
template <typename T,typename ...Args> inline void read(T &x,Args &...args){read(x);read(args...);}
template<typename T> inline void write(T x,char c){write(x),putchar(c);}
}
using namespace IO;
int a,b,n,logn,m[1005][1005],ans=INT_MAX;
int maxv[1005][1005],minv[1005][1005];
int query(int x, int y){
int maxn=0,minn=0;
maxn=max(maxv[x][y],max(maxv[x+n-(1<<logn)][y+n-(1<<logn)],max(maxv[x+n-(1<<logn)][y],maxv[x][y+n-(1<<logn)])));
minn=min(minv[x][y],min(minv[x+n-(1<<logn)][y+n-(1<<logn)],min(minv[x+n-(1<<logn)][y],minv[x][y+n-(1<<logn)])));
return maxn-minn;
}
signed main(){
read(a,b,n);
for(int i=0;i<a;++i)
for(int j=0;j<b;++j){
read(m[i][j]);
maxv[i][j]=minv[i][j]=m[i][j];
}
logn=log2(n);
for(int k=0;k<logn;++k)
for(int i=0;i+(1<<k)<a;++i)
for(int j=0;j+(1<<k)<b;++j){
maxv[i][j]=max(maxv[i][j],max(maxv[i+(1<<k)][j+(1<<k)],max(maxv[i+(1<<k)][j],maxv[i][j+(1<<k)])));
minv[i][j]=min(minv[i][j],min(minv[i+(1<<k)][j+(1<<k)],min(minv[i+(1<<k)][j],minv[i][j+(1<<k)])));
}
for(int i=0;i<=a-n;++i)
for(int j=0;j<=b-n;++j)
ans=min(ans,query(i,j));
write(ans);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 113ms
memory: 24708kb
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: 1192kb
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: 1ms
memory: 2572kb
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: 81ms
memory: 24708kb
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: 34ms
memory: 12920kb
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: 62ms
memory: 12936kb
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: 75ms
memory: 24708kb
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: 31ms
memory: 12920kb
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: 50ms
memory: 12936kb
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: 130ms
memory: 24708kb
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