답안 #378566

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378566 2021-03-17T01:49:35 Z rk42745417 Chessboard (IZhO18_chessboard) C++17
47 / 100
133 ms 262148 KB
#include <bits/stdc++.h>
using namespace std;

using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using ld = long double;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll LINF = 2e18;
const double EPS = 1e-9;
#define EMT ios::sync_with_stdio(0); cin.tie(0);

bool prime_test(int n) {
	for(int i = 2; i < n; i++)
		if(n % i == 0)
			return false;
	return true;
}
void solve(int n) {
	int k;
	cin >> k;
	vector<vector<int>> sum(n + 1, vector<int>(n + 1));
	for(int i = 0, a, b, c, d; i < k; i++) {
		cin >> a >> b >> c >> d;
		sum[a][b]++;
	}
	for(int i = 1; i <= n; i++)
		for(int j = 1, g = 0; j <= n; j++)
			g += sum[i][j], sum[i][j] = sum[i - 1][j] + g;
	//for(int i = 1; i <= n; i++)
		//for(int j = 1; j <= n; j++)
			//cout << sum[i][j] << " \n"[j == n];
	int ans = INF;
	for(int i = 1; i < n; i++) {
		if(n % i)
			continue;
		int res = 0, w = n / i;
		for(int j = 1; j <= w; j ++) {
			for(int k = 1; k <= w; k++) {
				if((j + k) & 1) {
					res += sum[j * i][k * i] - sum[j * i - i][k * i] - sum[j * i][k * i - i] + sum[j * i - i][k * i - i];
				}
				else {
					res += i * i - (sum[j * i][k * i] - sum[j * i - i][k * i] - sum[j * i][k * i - i] + sum[j * i - i][k * i - i]);
				}
			}
		}
		//cout << i << ' ' << res << ' ' << n * n - res << '\n';
		ans = min({ans, res, n * n - res});
	}
	cout << ans << '\n';
}
void solve_2(int n) {
	int cnt[2] = {0}, k;
	cin >> k;
	for(int i = 0, a, b, c, d; i < k; i++) {
		cin >> a >> b >> c >> d;
		cnt[(a + b) % 2]++;
	}
	ll a = 1LL * n * n / 2, b = 1LL * n * n - a;
	cout << min(cnt[1] + b - cnt[0], cnt[0] + a - cnt[1]) << '\n';
}
signed main() { EMT
	int n;
	cin >> n;
	if(prime_test(n))
		solve_2(n);
	else
		solve(n);
}
/*
6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 364 KB Output is correct
2 Correct 6 ms 364 KB Output is correct
3 Correct 14 ms 364 KB Output is correct
4 Correct 16 ms 364 KB Output is correct
5 Correct 20 ms 364 KB Output is correct
6 Correct 13 ms 364 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 13 ms 364 KB Output is correct
9 Correct 32 ms 364 KB Output is correct
10 Correct 18 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 14 ms 3948 KB Output is correct
17 Correct 25 ms 364 KB Output is correct
18 Correct 42 ms 4332 KB Output is correct
19 Correct 36 ms 3948 KB Output is correct
20 Correct 41 ms 3948 KB Output is correct
21 Correct 24 ms 364 KB Output is correct
22 Correct 6 ms 4332 KB Output is correct
23 Correct 20 ms 4076 KB Output is correct
24 Correct 36 ms 4204 KB Output is correct
25 Correct 10 ms 4076 KB Output is correct
26 Correct 24 ms 3948 KB Output is correct
27 Correct 30 ms 3948 KB Output is correct
28 Correct 39 ms 3948 KB Output is correct
29 Correct 10 ms 364 KB Output is correct
30 Correct 8 ms 4332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 364 KB Output is correct
2 Correct 6 ms 364 KB Output is correct
3 Correct 14 ms 364 KB Output is correct
4 Correct 16 ms 364 KB Output is correct
5 Correct 20 ms 364 KB Output is correct
6 Correct 13 ms 364 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 13 ms 364 KB Output is correct
9 Correct 32 ms 364 KB Output is correct
10 Correct 18 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 14 ms 3948 KB Output is correct
27 Correct 25 ms 364 KB Output is correct
28 Correct 42 ms 4332 KB Output is correct
29 Correct 36 ms 3948 KB Output is correct
30 Correct 41 ms 3948 KB Output is correct
31 Correct 24 ms 364 KB Output is correct
32 Correct 6 ms 4332 KB Output is correct
33 Correct 20 ms 4076 KB Output is correct
34 Correct 36 ms 4204 KB Output is correct
35 Correct 10 ms 4076 KB Output is correct
36 Correct 24 ms 3948 KB Output is correct
37 Correct 30 ms 3948 KB Output is correct
38 Correct 39 ms 3948 KB Output is correct
39 Correct 10 ms 364 KB Output is correct
40 Correct 8 ms 4332 KB Output is correct
41 Runtime error 133 ms 262148 KB Execution killed with signal 9
42 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 23 ms 364 KB Output is correct
10 Correct 6 ms 364 KB Output is correct
11 Correct 14 ms 364 KB Output is correct
12 Correct 16 ms 364 KB Output is correct
13 Correct 20 ms 364 KB Output is correct
14 Correct 13 ms 364 KB Output is correct
15 Correct 3 ms 364 KB Output is correct
16 Correct 13 ms 364 KB Output is correct
17 Correct 32 ms 364 KB Output is correct
18 Correct 18 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 14 ms 3948 KB Output is correct
35 Correct 25 ms 364 KB Output is correct
36 Correct 42 ms 4332 KB Output is correct
37 Correct 36 ms 3948 KB Output is correct
38 Correct 41 ms 3948 KB Output is correct
39 Correct 24 ms 364 KB Output is correct
40 Correct 6 ms 4332 KB Output is correct
41 Correct 20 ms 4076 KB Output is correct
42 Correct 36 ms 4204 KB Output is correct
43 Correct 10 ms 4076 KB Output is correct
44 Correct 24 ms 3948 KB Output is correct
45 Correct 30 ms 3948 KB Output is correct
46 Correct 39 ms 3948 KB Output is correct
47 Correct 10 ms 364 KB Output is correct
48 Correct 8 ms 4332 KB Output is correct
49 Runtime error 133 ms 262148 KB Execution killed with signal 9
50 Halted 0 ms 0 KB -