# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
987716 | 2024-05-23T12:13:41 Z | kim | The Kingdom of JOIOI (JOI17_joioi) | C++17 | 1 ms | 348 KB |
#include<bits/stdc++.h> using namespace std; int a[2005][2005]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n,m; cin>>n>>m; for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) cin>>a[i][j]; int l=0,r=1e9; while(l<r){ int mid=l+r>>1; bool ok=1; int cur=m,prev=m; for(int i=1;ok&&i<=n;++i,prev=cur){ for(int j=1;j<=cur;++j){ if(i!=1&&abs(a[i-1][j]-a[i][j])>mid) cur=j-1; else if(j!=1&&abs(a[i][j-1]-a[i][j])>mid) cur=j-1; } for(int j=cur+1;ok&&j<=m;++j){ if(j>prev&&abs(a[i-1][j]-a[i][j])>mid) ok=0; else if(j!=cur+1&&abs(a[i][j-1]-a[i][j])>mid) ok=0; } } if(ok){ r=mid; continue; } ok=1; cur=1,prev=1; for(int i=1;ok&&i<=n;++i,prev=cur){ for(int j=m;j>=cur;--j){ if(i!=1&&abs(a[i-1][j]-a[i][j])>mid) cur=j+1; else if(j!=m&&abs(a[i][j+1]-a[i][j])>mid) cur=j+1; } for(int j=cur-1;ok&&j>=1;--j){ if(j<prev&&abs(a[i-1][j]-a[i][j])>mid) ok=0; else if(j!=cur-1&&abs(a[i][j+1]-a[i][j])>mid) ok=0; } } if(ok) r=mid; else l=mid+1; } cout<<l; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |