Submission #837209

#TimeUsernameProblemLanguageResultExecution timeMemory
837209_martynasThe Kingdom of JOIOI (JOI17_joioi)C++11
100 / 100
1328 ms20044 KiB
#include <bits/stdc++.h> using namespace std; #warning change mxn const int mxn = 2005; const int inf = 2e9; int h, w; int mxa = 0; int a[mxn][mxn]; bool b[mxn][mxn]; int check() { int mnj = w; int mn = inf/2, mx = 0; for(int i = 0; i < h; i++) { for(int j = 0; j < mnj; j++) { if(b[i][j]) mnj = j; } for(int j = mnj; j < w; j++) { mn = min(mn, a[i][j]); mx = max(mx, a[i][j]); } } return mx-mn; } bool solve(int k) { for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) b[i][j] = mxa-a[i][j]>k; bool ok = false; // check ok = ok || (check() <= k); // reverse rows for(int i = 0; i < h; i++) for(int j = 0; j < w/2; j++) swap(a[i][j], a[i][w-j-1]); for(int i = 0; i < h; i++) for(int j = 0; j < w/2; j++) swap(b[i][j], b[i][w-j-1]); // check ok = ok || (check() <= k); // reverse cols for(int i = 0; i < h/2; i++) for(int j = 0; j < w; j++) swap(a[i][j], a[h-i-1][j]); for(int i = 0; i < h/2; i++) for(int j = 0; j < w; j++) swap(b[i][j], b[h-i-1][j]); // check ok = ok || (check() <= k); // reverse rows for(int i = 0; i < h; i++) for(int j = 0; j < w/2; j++) swap(a[i][j], a[i][w-j-1]); for(int i = 0; i < h; i++) for(int j = 0; j < w/2; j++) swap(b[i][j], b[i][w-j-1]); // check ok = ok || (check() <= k); // reverse cols for(int i = 0; i < h/2; i++) for(int j = 0; j < w; j++) swap(a[i][j], a[h-i-1][j]); for(int i = 0; i < h/2; i++) for(int j = 0; j < w; j++) swap(b[i][j], b[h-i-1][j]); return ok; } int main(int argc, char const *argv[]) { ios::sync_with_stdio(0); cin.tie(0); cin >> h >> w; for(int i = 0; i < h; i++) { for(int j = 0; j < w; j++) { cin >> a[i][j]; mxa = max(mxa, a[i][j]); } } int lo = 0, hi = inf/2; while(lo < hi) { int m = (lo+hi)/2; if(solve(m)) { hi = m; } else { lo = m+1; } } cout << lo << "\n"; return 0; }

Compilation message (stderr)

joioi.cpp:5:2: warning: #warning change mxn [-Wcpp]
    5 | #warning change mxn
      |  ^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...