Submission #1277761

#TimeUsernameProblemLanguageResultExecution timeMemory
1277761wedonttalkanymoreThe Kingdom of JOIOI (JOI17_joioi)C++20
0 / 100
1 ms332 KiB
#include <bits/stdc++.h> /* Brute to win */ using namespace std; using ll = long long; #define int long long #define pii pair<ll, ll> #define fi first #define se second const ll N = 2e3 + 5, inf = 1e18, mod = 1e9 + 7, block = 320, lim = 19; int h, w, a[N][N], b[N][N]; int minn = inf; void rolate() { for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { b[i][j] = a[w - j + 1][i]; } } swap(h, w); for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { a[i][j] = b[i][j]; } } } bool check(int mid) { int vmax = 0, vmin = inf, last = w; for (int i = 1; i <= h; i++) { for (int j = 1; j <= last; j++) { if (a[i][j] - minn > mid) { last = j - 1; break; } } for (int j = last + 1; j <= w; j++) { vmin = min(vmin, a[i][j]); vmax = max(vmax, a[i][j]); } } return vmax - vmin <= mid; } signed main() { ios::sync_with_stdio(false); cin.tie(0); if (fopen(".inp", "r")) { freopen(".inp", "r", stdin); freopen(".out", "w", stdout); } cin >> h >> w; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { cin >> a[i][j]; minn = min(minn, a[i][j]); } } int ans = inf; for (int i = 1; i <= 4; i++) { int l = 1, r = 1e9, res = inf; while(l <= r) { int mid = (l + r) / 2; if (check(mid)) { res = mid; r = mid - 1; } else l = mid + 1; } ans = min(ans, res); rolate(); } cout << ans; return 0; }

Compilation message (stderr)

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