Submission #68244

# Submission time Handle Problem Language Result Execution time Memory
68244 2018-08-16T09:44:58 Z Nurlykhan The Kingdom of JOIOI (JOI17_joioi) C++17
15 / 100
96 ms 3880 KB
#include <bits/stdc++.h>

#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())
#define pii pair<int, int>
#define mp make_pair
#define f first
#define ll long long
#define ld long double
#define s second
#define vec vector<int>

using namespace std;

const int N = (int) 2e3 + 10;
const int M = (int) 2018 * 2018;
const int K = (int) 15;
const int INF = (int) 1e9 + 7;
const int mod = (int) 998244353;
const ld EPS = (ld) 1e-9;
const ll LINF = (ll) 1e18;

int n, m;
int a[N][N], b[N][N], c[N][N], ptr[N];
bool boo[N][N];

bool solve(int diff) {
	int mx_i = 1, mx_j = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (a[mx_i][mx_j] < a[i][j]) {
				mx_i = i;
				mx_j = j;
			}
		}
	}
	// a[mx_i][mx_j] <= a[i][j] + diff
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (a[mx_i][mx_j] <= diff + a[i][j]) {
				boo[i][j] = 1;
			} else {
				boo[i][j] = 0;
			}
		}
	}
	ptr[0] = m;
	for (int i = 1; i <= n; i++) {
		ptr[i] = ptr[i - 1];
		for (int j = 1; j <= ptr[i - 1]; j++) {
			if (!boo[i][j]) {
				ptr[i] = j - 1;
				break;
			}
		}
	}
	int mx = 0, mn = INF;
	for (int i = 1; i <= n; i++) {
		for (int j = ptr[i] + 1; j <= m; j++) {
			mx = max(mx, a[i][j]);
			mn = min(mn, a[i][j]);
		}
	}
	if (mx_j > ptr[mx_i]) 
		return false;
	return mx - mn <= diff;
}

void mirror() {
	for (int i = 1; i <= n / 2; i++) {
		for (int j = 1; j <= m; j++) {
			swap(a[i][j], a[n - i + 1][j]);
		}
	}
}

void rotate() {
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			b[j][n - i + 1] = a[i][j];
		}
	}
	swap(n, m);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			a[i][j] = b[i][j];
		}
	}
}

bool ok(int diff) {
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			a[i][j] = c[i][j];
		}
	}
	for (int i = 0; i < 4; i++) {
		if (solve(diff)) return true;
		mirror();
		if (solve(diff)) return true;
		mirror();
		rotate();
	}
	return false;
}

int main() {
	#ifdef sony
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	srand(time(0));
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			scanf("%d", &c[i][j]);
		}
	}
	int l = 1, r = INF;
	int ans;
	while (l <= r) {
		int mid = (l + r) / 2;
		if (ok(mid)) {
			r = mid - 1;
			ans = mid;
		} else {
			l = mid + 1;
		}
	}
	cout << ans;
	return 0;	
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:117:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &c[i][j]);
    ~~~~~^~~~~~~~~~~~~~~~
joioi.cpp:131:7: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
  cout << ans;
  ~~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 3 ms 620 KB Output is correct
8 Correct 3 ms 668 KB Output is correct
9 Correct 4 ms 716 KB Output is correct
10 Correct 3 ms 720 KB Output is correct
11 Correct 3 ms 720 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 3 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 3 ms 620 KB Output is correct
8 Correct 3 ms 668 KB Output is correct
9 Correct 4 ms 716 KB Output is correct
10 Correct 3 ms 720 KB Output is correct
11 Correct 3 ms 720 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 3 ms 724 KB Output is correct
15 Correct 5 ms 2644 KB Output is correct
16 Correct 23 ms 3796 KB Output is correct
17 Correct 54 ms 3880 KB Output is correct
18 Incorrect 96 ms 3880 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 3 ms 620 KB Output is correct
8 Correct 3 ms 668 KB Output is correct
9 Correct 4 ms 716 KB Output is correct
10 Correct 3 ms 720 KB Output is correct
11 Correct 3 ms 720 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 3 ms 724 KB Output is correct
15 Correct 5 ms 2644 KB Output is correct
16 Correct 23 ms 3796 KB Output is correct
17 Correct 54 ms 3880 KB Output is correct
18 Incorrect 96 ms 3880 KB Output isn't correct
19 Halted 0 ms 0 KB -