답안 #993469

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
993469 2024-06-05T17:50:37 Z horezushol The Kingdom of JOIOI (JOI17_joioi) C++14
0 / 100
935 ms 69864 KB
#include<bits/stdc++.h>
#define F first
#define S second
#define SZ(x) ((ll)(x).size())
inline void outlast() {
	#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	#endif
}
const char nl = '\n';
using namespace std;
using ll = long long;
// head

const ll N = 2100;
vector<vector<ll>> a(N, vector<ll> (N, 0));
ll h, w;

vector<vector<ll>> CIRCLE(const vector<vector<ll>>& matrix) {
    vector<vector<ll>> rotated(N, vector<ll>(N));    
    for (ll i = 1; i <= h; i++) {
        for (ll j = 1; j <= w; j++) {
            rotated[j][h-i+1] = matrix[i][j];
        }
    }
    swap(h, w);
    return rotated;
}


void solve() {
	cin >> h >> w;
	for (ll i = 1; i <= h; i ++) {
		for (ll j = 1; j <= w; j ++) {
			cin >> a[i][j];
		}
	}
	ll L = 0, R = 1e9;
	while (L + 1 < R) {
		ll mid = (L + R) / 2;
		bool ok = false;
		for (ll i = 0; i < 4; i ++) {
			a = CIRCLE(a);
			ll val = LLONG_MAX, posx = 0, posy = 0;
			for (ll i = 1; i <= h; i ++) {
				for (ll j = 1; j <= w; j ++) {
					if (a[i][j] < val) {
						val = a[i][j];
						posx = i;
						posy = j;
					}
				}
			}
			vector<ll> row(N, 0);
			for (ll i = 1; i <= h; i ++) {
				for (ll j = 1; j <= w; j ++) {
					if (a[i][j] <= val + mid) {
						row[i] ++;
					} else {
						break;
					}
				}
			}
			for (ll i = 2; i <= h; i ++) {
				row[i] = min(row[i], row[i-1]);
			}
			ll mn = LLONG_MAX, mx = LLONG_MIN;
			for (ll i = 1; i <= h; i ++) {
				for (ll j = row[i]+1; j <= w; j ++) {
					mn = min(mn, a[i][j]);
					mx = max(mx, a[i][j]);
				}
			}
			if (row[posx] >= posy && (mx == LLONG_MIN || mx - mn <= mid)) {
				ok = true;
			}
		}
		if (ok) {
			R = mid;
		} else {
			L = mid;
		}
	}
	cout << R;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	outlast();
	ll tst = 1;
	// cin >> tst;
	while (tst --) {
		solve();
		cout << nl;
	}
}

Compilation message

joioi.cpp: In function 'void outlast()':
joioi.cpp:7:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |  freopen("in.txt", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
joioi.cpp:8:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |  freopen("out.txt", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 935 ms 69864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 935 ms 69864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 935 ms 69864 KB Output isn't correct
2 Halted 0 ms 0 KB -