답안 #378876

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378876 2021-03-17T06:52:56 Z cheissmart Chessboard (IZhO18_chessboard) C++14
47 / 100
2000 ms 1900 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 0 ms 364 KB Output is correct
3 Correct 1 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 35 ms 1260 KB Output is correct
2 Correct 10 ms 640 KB Output is correct
3 Correct 22 ms 1004 KB Output is correct
4 Correct 24 ms 1004 KB Output is correct
5 Correct 30 ms 1132 KB Output is correct
6 Correct 20 ms 876 KB Output is correct
7 Correct 5 ms 492 KB Output is correct
8 Correct 20 ms 876 KB Output is correct
9 Correct 50 ms 1772 KB Output is correct
10 Correct 28 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 384 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 1 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 384 KB Output is correct
13 Correct 2 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 21 ms 748 KB Output is correct
17 Correct 40 ms 1644 KB Output is correct
18 Correct 76 ms 1900 KB Output is correct
19 Correct 365 ms 1772 KB Output is correct
20 Correct 406 ms 1900 KB Output is correct
21 Correct 38 ms 1644 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 56 ms 1004 KB Output is correct
24 Correct 70 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 70 ms 1388 KB Output is correct
28 Correct 75 ms 1772 KB Output is correct
29 Correct 16 ms 876 KB Output is correct
30 Correct 3 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 1260 KB Output is correct
2 Correct 10 ms 640 KB Output is correct
3 Correct 22 ms 1004 KB Output is correct
4 Correct 24 ms 1004 KB Output is correct
5 Correct 30 ms 1132 KB Output is correct
6 Correct 20 ms 876 KB Output is correct
7 Correct 5 ms 492 KB Output is correct
8 Correct 20 ms 876 KB Output is correct
9 Correct 50 ms 1772 KB Output is correct
10 Correct 28 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 384 KB Output is correct
23 Correct 2 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 21 ms 748 KB Output is correct
27 Correct 40 ms 1644 KB Output is correct
28 Correct 76 ms 1900 KB Output is correct
29 Correct 365 ms 1772 KB Output is correct
30 Correct 406 ms 1900 KB Output is correct
31 Correct 38 ms 1644 KB Output is correct
32 Correct 2 ms 364 KB Output is correct
33 Correct 56 ms 1004 KB Output is correct
34 Correct 70 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 70 ms 1388 KB Output is correct
38 Correct 75 ms 1772 KB Output is correct
39 Correct 16 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 1772 KB Output is correct
43 Correct 176 ms 1644 KB Output is correct
44 Correct 79 ms 1772 KB Output is correct
45 Correct 54 ms 1900 KB Output is correct
46 Correct 372 ms 1772 KB Output is correct
47 Correct 50 ms 1772 KB Output is correct
48 Correct 130 ms 1644 KB Output is correct
49 Correct 73 ms 1644 KB Output is correct
50 Correct 1820 ms 1772 KB Output is correct
51 Correct 1941 ms 1900 KB Output is correct
52 Correct 1809 ms 1772 KB Output is correct
53 Correct 1932 ms 1772 KB Output is correct
54 Correct 1784 ms 1772 KB Output is correct
55 Execution timed out 2004 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 0 ms 364 KB Output is correct
3 Correct 1 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 35 ms 1260 KB Output is correct
10 Correct 10 ms 640 KB Output is correct
11 Correct 22 ms 1004 KB Output is correct
12 Correct 24 ms 1004 KB Output is correct
13 Correct 30 ms 1132 KB Output is correct
14 Correct 20 ms 876 KB Output is correct
15 Correct 5 ms 492 KB Output is correct
16 Correct 20 ms 876 KB Output is correct
17 Correct 50 ms 1772 KB Output is correct
18 Correct 28 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 384 KB Output is correct
31 Correct 2 ms 364 KB Output is correct
32 Correct 1 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 76 ms 1900 KB Output is correct
37 Correct 365 ms 1772 KB Output is correct
38 Correct 406 ms 1900 KB Output is correct
39 Correct 38 ms 1644 KB Output is correct
40 Correct 2 ms 364 KB Output is correct
41 Correct 56 ms 1004 KB Output is correct
42 Correct 70 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 70 ms 1388 KB Output is correct
46 Correct 75 ms 1772 KB Output is correct
47 Correct 16 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 1772 KB Output is correct
51 Correct 176 ms 1644 KB Output is correct
52 Correct 79 ms 1772 KB Output is correct
53 Correct 54 ms 1900 KB Output is correct
54 Correct 372 ms 1772 KB Output is correct
55 Correct 50 ms 1772 KB Output is correct
56 Correct 130 ms 1644 KB Output is correct
57 Correct 73 ms 1644 KB Output is correct
58 Correct 1820 ms 1772 KB Output is correct
59 Correct 1941 ms 1900 KB Output is correct
60 Correct 1809 ms 1772 KB Output is correct
61 Correct 1932 ms 1772 KB Output is correct
62 Correct 1784 ms 1772 KB Output is correct
63 Execution timed out 2004 ms 1900 KB Time limit exceeded
64 Halted 0 ms 0 KB -