# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
751729 | 2023-06-01T10:30:51 Z | guagua0407 | The Kingdom of JOIOI (JOI17_joioi) | C++17 | 1 ms | 340 KB |
//#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define int ll #define pii pair<int,int> #define f first #define s second #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } const int mxn=2e3+5; int a[mxn][mxn]; vector<int> vec; int n,m; int mn=1e9; int mx=0; bool ok(int mid){ int l=upper_bound(all(vec),mn+mid)-vec.begin()-1; int r=lower_bound(all(vec),mx-mid)-vec.begin(); if(l<r-1) return false; vector<vector<int>> vis(n,vector<int>(m,0)); for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(a[i][j]<=min(mn+mid,mx-mid-1)){ vis[i][j]=-1; } else if(a[i][j]>=max(mn+mid+1,mx-mid)){ vis[i][j]=1; } } } int prv=0; for(int i=0;i<n;i++){ int cur=0; int cnt=0; for(int j=0;j<m;j++){ if(vis[i][j]!=0 and vis[i][j]!=cur){ cur=vis[i][j]; cnt++; } } if(cnt>=3) return false; if(cnt==2){ if(prv==0) prv=cur; else if(prv!=cur) return false; } } prv=0; for(int i=0;i<m;i++){ int cur=0; int cnt=0; for(int j=0;j<n;j++){ if(vis[j][i]!=0 and vis[j][i]!=cur){ cur=vis[j][i]; cnt++; } } if(cnt>=3) return false; if(cnt==2){ if(prv==0) prv=cur; else if(prv!=cur) return false; } } return true; } signed main() {_ cin>>n>>m; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cin>>a[i][j]; vec.push_back(a[i][j]); mx=max(mx,a[i][j]); mn=min(mn,a[i][j]); } } sort(all(vec)); int l=0,r=mx-mn; while(l<r){ int mid=(l+r)/2; if(ok(mid)){ r=mid; } else{ l=mid+1; } } cout<<l<<'\n'; return 0; } //maybe its multiset not set
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Incorrect | 1 ms | 340 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Incorrect | 1 ms | 340 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Incorrect | 1 ms | 340 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |