Submission #1109354

#TimeUsernameProblemLanguageResultExecution timeMemory
1109354mariaclaraThe Kingdom of JOIOI (JOI17_joioi)C++17
0 / 100
1 ms2384 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef tuple<ll,ll,ll> trio; typedef pair<int,int> pii; const int MAXN = 2e5+5; const ll INF = 1e9; #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define mk make_pair #define pb push_back #define fr first #define sc second int n, m, max_val, min_val = 1e9, v[2005][2005], color[2005][2005]; bool check(int dif) { int a = 0, b = 0, c = 0, d = -1; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { color[i][j] = 0; if(max_val - dif >= v[i][j]) color[i][j] = 1; if(min_val + dif <= v[i][j]) { if(color[i][j] == 1) return 0; color[i][j] = -1; } } } for(int i = 1; i <= n; i++) { for(int j = 1, last = 0, cnt = 0; j <= m; j++) { if(color[i][j] == 0) continue; cnt += (last != color[i][j]); last = color[i][j]; if(cnt > 2) return 0; } } for(int j = 1; j <= m; j++) { for(int i = 1, last = 0, cnt = 0; i <= n; i++) { if(color[i][j] == 0) continue; cnt += (last != color[i][j]); last = color[i][j]; if(cnt > 2) return 0; } } return 1; } int busca() { int l = 1, r = max_val - min_val; while(l <= r) { int mid = (l+r)/2; if(check(mid)) r = mid-1; else l = mid+1; } return r; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { cin >> v[i][j]; min_val = min(min_val, v[i][j]); max_val = max(max_val, v[i][j]); } } //cout << check(12) << "\n"; cout << busca(); }

Compilation message (stderr)

joioi.cpp: In function 'bool check(int)':
joioi.cpp:20:9: warning: unused variable 'a' [-Wunused-variable]
   20 |     int a = 0, b = 0, c = 0, d = -1;
      |         ^
joioi.cpp:20:16: warning: unused variable 'b' [-Wunused-variable]
   20 |     int a = 0, b = 0, c = 0, d = -1;
      |                ^
joioi.cpp:20:23: warning: unused variable 'c' [-Wunused-variable]
   20 |     int a = 0, b = 0, c = 0, d = -1;
      |                       ^
joioi.cpp:20:30: warning: unused variable 'd' [-Wunused-variable]
   20 |     int a = 0, b = 0, c = 0, d = -1;
      |                              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...