답안 #378873

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378873 2021-03-17T06:49:59 Z cheissmart Chessboard (IZhO18_chessboard) C++14
47 / 100
2000 ms 1920 KB
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;
const ll oo = 1e18;

signed main()
{
	IO_OP;

	int n, k;
	cin >> n >> k;
	V<array<int, 4>> a(k);
	for(int i = 0; i < k; i++) {
		for(int j = 0; j < 4; j++)
			cin >> a[i][j], a[i][j]--;
	}

	ll ans = oo;
	auto go = [&] (int b) {
		int m = n / b;
		ll white = (ll) m * m / 2 * b * b, black = (ll) n * n - white;
		ll wb = 0;
		auto solve = [&] (int x, int y) {
			if(x < 0 || y < 0) return 0LL;
			int l = (x + 1) % (2 * b), r = (y + 1) % (2 * b);
			ll W = 0, B = 0;
			B += (ll) min(l, b) * min(r, b);
			B += (ll) max(0, l - b) * max(0, r - b);
			W += (ll) min(l, b) * max(0, r - b);;
			W += (ll) max(0, l - b) * min(r, b);
			if((x / (2 * b) * (2 * b) / b + y / (2 * b) * (2 * b) / b) % 2)
				swap(W, B);
			return W - B;
		};
		for(int i = 0; i < k; i++) {
			wb += solve(a[i][2], a[i][3]) - solve(a[i][0] - 1, a[i][3]) - solve(a[i][2], a[i][1] - 1) + solve(a[i][0] - 1, a[i][1] - 1);
		}
		return black + wb;
	};

	for(int i = 1; i < n; i++) {
		if(n % i == 0) {
			ll t = go(i);
			t = min(t, (ll) n * n - t);
			ans = min(ans, t);
		}
	}
	cout << ans << '\n';

}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 1260 KB Output is correct
2 Correct 9 ms 620 KB Output is correct
3 Correct 23 ms 1004 KB Output is correct
4 Correct 27 ms 1004 KB Output is correct
5 Correct 31 ms 1132 KB Output is correct
6 Correct 20 ms 896 KB Output is correct
7 Correct 5 ms 492 KB Output is correct
8 Correct 20 ms 876 KB Output is correct
9 Correct 54 ms 1920 KB Output is correct
10 Correct 33 ms 1132 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 2 ms 364 KB Output is correct
5 Correct 1 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 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 2 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 1 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 2 ms 364 KB Output is correct
5 Correct 1 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 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 2 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 21 ms 748 KB Output is correct
17 Correct 40 ms 1644 KB Output is correct
18 Correct 74 ms 1920 KB Output is correct
19 Correct 371 ms 1772 KB Output is correct
20 Correct 421 ms 1920 KB Output is correct
21 Correct 38 ms 1644 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 58 ms 1004 KB Output is correct
24 Correct 68 ms 1772 KB Output is correct
25 Correct 12 ms 492 KB Output is correct
26 Correct 43 ms 1260 KB Output is correct
27 Correct 72 ms 1388 KB Output is correct
28 Correct 75 ms 1772 KB Output is correct
29 Correct 19 ms 876 KB Output is correct
30 Correct 3 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 1260 KB Output is correct
2 Correct 9 ms 620 KB Output is correct
3 Correct 23 ms 1004 KB Output is correct
4 Correct 27 ms 1004 KB Output is correct
5 Correct 31 ms 1132 KB Output is correct
6 Correct 20 ms 896 KB Output is correct
7 Correct 5 ms 492 KB Output is correct
8 Correct 20 ms 876 KB Output is correct
9 Correct 54 ms 1920 KB Output is correct
10 Correct 33 ms 1132 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 2 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 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 2 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 21 ms 748 KB Output is correct
27 Correct 40 ms 1644 KB Output is correct
28 Correct 74 ms 1920 KB Output is correct
29 Correct 371 ms 1772 KB Output is correct
30 Correct 421 ms 1920 KB Output is correct
31 Correct 38 ms 1644 KB Output is correct
32 Correct 2 ms 364 KB Output is correct
33 Correct 58 ms 1004 KB Output is correct
34 Correct 68 ms 1772 KB Output is correct
35 Correct 12 ms 492 KB Output is correct
36 Correct 43 ms 1260 KB Output is correct
37 Correct 72 ms 1388 KB Output is correct
38 Correct 75 ms 1772 KB Output is correct
39 Correct 19 ms 876 KB Output is correct
40 Correct 3 ms 364 KB Output is correct
41 Correct 329 ms 1644 KB Output is correct
42 Correct 82 ms 1804 KB Output is correct
43 Correct 175 ms 1644 KB Output is correct
44 Correct 87 ms 1772 KB Output is correct
45 Correct 54 ms 1900 KB Output is correct
46 Correct 371 ms 1772 KB Output is correct
47 Correct 48 ms 1644 KB Output is correct
48 Correct 138 ms 1644 KB Output is correct
49 Correct 73 ms 1644 KB Output is correct
50 Correct 1828 ms 1772 KB Output is correct
51 Correct 1947 ms 1900 KB Output is correct
52 Correct 1816 ms 1772 KB Output is correct
53 Correct 1940 ms 1772 KB Output is correct
54 Correct 1800 ms 1900 KB Output is correct
55 Execution timed out 2021 ms 1900 KB Time limit exceeded
56 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 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 41 ms 1260 KB Output is correct
10 Correct 9 ms 620 KB Output is correct
11 Correct 23 ms 1004 KB Output is correct
12 Correct 27 ms 1004 KB Output is correct
13 Correct 31 ms 1132 KB Output is correct
14 Correct 20 ms 896 KB Output is correct
15 Correct 5 ms 492 KB Output is correct
16 Correct 20 ms 876 KB Output is correct
17 Correct 54 ms 1920 KB Output is correct
18 Correct 33 ms 1132 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 2 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 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 2 ms 364 KB Output is correct
32 Correct 2 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 21 ms 748 KB Output is correct
35 Correct 40 ms 1644 KB Output is correct
36 Correct 74 ms 1920 KB Output is correct
37 Correct 371 ms 1772 KB Output is correct
38 Correct 421 ms 1920 KB Output is correct
39 Correct 38 ms 1644 KB Output is correct
40 Correct 2 ms 364 KB Output is correct
41 Correct 58 ms 1004 KB Output is correct
42 Correct 68 ms 1772 KB Output is correct
43 Correct 12 ms 492 KB Output is correct
44 Correct 43 ms 1260 KB Output is correct
45 Correct 72 ms 1388 KB Output is correct
46 Correct 75 ms 1772 KB Output is correct
47 Correct 19 ms 876 KB Output is correct
48 Correct 3 ms 364 KB Output is correct
49 Correct 329 ms 1644 KB Output is correct
50 Correct 82 ms 1804 KB Output is correct
51 Correct 175 ms 1644 KB Output is correct
52 Correct 87 ms 1772 KB Output is correct
53 Correct 54 ms 1900 KB Output is correct
54 Correct 371 ms 1772 KB Output is correct
55 Correct 48 ms 1644 KB Output is correct
56 Correct 138 ms 1644 KB Output is correct
57 Correct 73 ms 1644 KB Output is correct
58 Correct 1828 ms 1772 KB Output is correct
59 Correct 1947 ms 1900 KB Output is correct
60 Correct 1816 ms 1772 KB Output is correct
61 Correct 1940 ms 1772 KB Output is correct
62 Correct 1800 ms 1900 KB Output is correct
63 Execution timed out 2021 ms 1900 KB Time limit exceeded
64 Halted 0 ms 0 KB -