# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
706359 | 2023-03-06T10:30:11 Z | Baytoro | The Kingdom of JOIOI (JOI17_joioi) | C++17 | 1 ms | 340 KB |
#include <bits/stdc++.h> using namespace std; #define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fr first #define sc second #define endl '\n' #define ll long long #define int long long void fopn(string name){ freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } const ll INF=1e18,mod=998244353; const int N=2005; int a[N][N],tmp[N][N]; int n,m; int calc(int x){ int mn=INF,mx=-INF; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++) mn=min(mn,tmp[i][j]),mx=max(mx,tmp[i][j]); } for(int i=1, l=m+1;i<=n;i++){ for(int j=1;j<l;j++){ if(tmp[i][j]-mn>x){ l=j; break; } } for(int j=l+1;j<=m;j++){ if(mx-tmp[i][j]>x) return false; } } return true; } int check(int x){ for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) tmp[i][j]=a[i][j]; for(int I=0;I<2;I++){ for(int J=0;J<2;J++){ if(calc(x)) return true; for(int i=1;i<=n;i++){ for(int l=1,r=m;l<r;l++,r--){ swap(tmp[i][l],tmp[i][r]); } } } for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) tmp[i][j]=-tmp[i][j]; } return false; } void solve(){ cin>>n>>m; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>a[i][j]; } } int l=-1,r=1e9; while(r-l>1){ int md=(l+r)/2; if(check(md)) r=md; else l=md; } cout<<r; } main(){ //fopn("cbarn"); ios; int T=1; //cin>>T; while(T--){ solve(); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Incorrect | 0 ms | 340 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Incorrect | 0 ms | 340 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Incorrect | 0 ms | 340 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |