제출 #1255120

#제출 시각아이디문제언어결과실행 시간메모리
1255120minggaThe Kingdom of JOIOI (JOI17_joioi)C++20
100 / 100
545 ms31844 KiB
// Author: caption_mingle #include "bits/stdc++.h" using namespace std; #define ln "\n" #define pb push_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define ll long long const int mod = 1e9 + 7; const int inf = 2e9; const int N = 2005; int n, m, a[N][N], b[N][N], mn; bool check(int mid) { int mx_m = m; for(int i = 1; i <= n; i++) { for(int j = 1; j <= mx_m; j++) { if(a[i][j] > mn + mid) { mx_m = j - 1; break; } b[i][j] = 1; } } int mn1 = inf, mx1 = -inf; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { if(b[i][j]) { b[i][j] = 0; continue; } mn1 = min(mn1, a[i][j]); mx1 = max(mx1, a[i][j]); } } if(mx1 - mn1 <= mid or mx1 == -inf) return 1; mx_m = m; for(int i = n; i > 0; i--) { for(int j = 1; j <= mx_m; j++) { if(a[i][j] > mn + mid) { mx_m = j - 1; break; } b[i][j] = 1; } } mn1 = inf, mx1 = -inf; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { if(b[i][j]) { b[i][j] = 0; continue; } mn1 = min(mn1, a[i][j]); mx1 = max(mx1, a[i][j]); } } if(mx1 - mn1 <= mid or mx1 == -inf) return 1; int mn_m = 1; for(int i = n; i > 0; i--) { for(int j = m; j >= mn_m; j--) { if(a[i][j] > mn + mid) { mn_m = j + 1; break; } b[i][j] = 1; } } mn1 = inf, mx1 = -inf; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { if(b[i][j]) { b[i][j] = 0; continue; } mn1 = min(mn1, a[i][j]); mx1 = max(mx1, a[i][j]); } } if(mx1 - mn1 <= mid or mx1 == -inf) return 1; mn_m = 1; for(int i = 1; i <= n; i++) { for(int j = m; j >= mn_m; j--) { if(a[i][j] > mn + mid) { mn_m = j + 1; break; } b[i][j] = 1; } } mn1 = inf, mx1 = -inf; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { if(b[i][j]) { b[i][j] = 0; continue; } mn1 = min(mn1, a[i][j]); mx1 = max(mx1, a[i][j]); } } if(mx1 - mn1 <= mid or mx1 == -inf) return 1; return 0; } signed main() { cin.tie(0) -> sync_with_stdio(0); #define task "" if(fopen(task ".INP", "r")) { freopen(task ".INP", "r", stdin); freopen(task ".OUT", "w", stdout); } cin >> n >> m; mn = inf; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { cin >> a[i][j]; mn = min(mn, a[i][j]); } } int l = 0, r = 1e9, ans; while(l <= r) { int m = (l + r) >> 1; if(check(m)) { ans = m; r = m - 1; } else l = m + 1; } cout << ans << ln; cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC; }

컴파일 시 표준 에러 (stderr) 메시지

joioi.cpp: In function 'int main()':
joioi.cpp:114:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  114 |                 freopen(task ".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
joioi.cpp:115:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  115 |                 freopen(task ".OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...