답안 #378732

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378732 2021-03-17T03:36:12 Z Kevin_Zhang_TW Chessboard (IZhO18_chessboard) C++17
70 / 100
2000 ms 4844 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif

#define int ll

const int MAX_N = 300010;

int n, k;
vector<tuple<int,int,int,int>> subr;

ll calgood(int w, int x1, int y1, int x2, int y2) {

//	{
//	ll res = 0;
//	for (int i = x1;i <= x2;++i)
//		for (int j = y1;j <= y2;++j) {
//			int need = (1^(i/w) ^ (j/w))&1;
//			res += need;
//		}
//	return res;
//	}

	ll res = 0;
	ll a = 0, b = 0, c = 0, d = 0;
	for (int i = x1;i <= x2;++i) {
		if ((1^(i/w)^(y1/w))&1) ++a;
		else ++b;
	}
	for (int i = y1;i <= y2;++i) {
		if ((y1/w&1) == (i/w&1)) 
			res += b;
		else
			res += a;
	}
	return res;
}
ll calcost(int wid) {
	ll res = calgood(wid, 0, 0, n-1, n-1);
	for (auto [x1, y1, x2, y2] : subr) {
		ll area = 1ll * (x2-x1+1) * (y2-y1+1);
		ll good = calgood(wid, x1, y1, x2, y2);
		ll bad = area - good;
		res -= good;
		res += bad;
	}

	return min(res, 1ll * n * n - res);
}
int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> k;
	DE(n, k);

	//if (n > 1000) return -1;
	subr.resize(k);
	for (auto &[x1, y1, x2, y2] : subr)
		cin >> x1 >> y1 >> x2 >> y2, --x1, --x2, --y1, --y2;

	ll res = 1ll * n * n;

	for (int i = 1;i < n;++i)
		if (n % i == 0)
			chmin(res, calcost(i));

	cout << res << '\n';
}

Compilation message

chessboard.cpp: In function 'll calgood(ll, ll, ll, ll, ll)':
chessboard.cpp:38:19: warning: unused variable 'c' [-Wunused-variable]
   38 |  ll a = 0, b = 0, c = 0, d = 0;
      |                   ^
chessboard.cpp:38:26: warning: unused variable 'd' [-Wunused-variable]
   38 |  ll a = 0, b = 0, c = 0, d = 0;
      |                          ^
chessboard.cpp: In function 'int32_t main()':
chessboard.cpp:14:17: warning: statement has no effect [-Wunused-value]
   14 | #define DE(...) 0
      |                 ^
chessboard.cpp:66:2: note: in expansion of macro 'DE'
   66 |  DE(n, k);
      |  ^~
# 결과 실행 시간 메모리 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 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 2284 KB Output is correct
2 Correct 10 ms 1260 KB Output is correct
3 Correct 21 ms 2412 KB Output is correct
4 Correct 20 ms 2540 KB Output is correct
5 Correct 27 ms 2924 KB Output is correct
6 Correct 18 ms 2156 KB Output is correct
7 Correct 5 ms 748 KB Output is correct
8 Correct 18 ms 2284 KB Output is correct
9 Correct 52 ms 4332 KB Output is correct
10 Correct 29 ms 2796 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 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 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
# 결과 실행 시간 메모리 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 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 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 12 ms 1136 KB Output is correct
17 Correct 31 ms 2924 KB Output is correct
18 Correct 45 ms 3436 KB Output is correct
19 Correct 97 ms 3052 KB Output is correct
20 Correct 114 ms 3436 KB Output is correct
21 Correct 35 ms 2924 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 23 ms 1644 KB Output is correct
24 Correct 42 ms 3180 KB Output is correct
25 Correct 5 ms 620 KB Output is correct
26 Correct 24 ms 2156 KB Output is correct
27 Correct 34 ms 2412 KB Output is correct
28 Correct 41 ms 3308 KB Output is correct
29 Correct 13 ms 1388 KB Output is correct
30 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 2284 KB Output is correct
2 Correct 10 ms 1260 KB Output is correct
3 Correct 21 ms 2412 KB Output is correct
4 Correct 20 ms 2540 KB Output is correct
5 Correct 27 ms 2924 KB Output is correct
6 Correct 18 ms 2156 KB Output is correct
7 Correct 5 ms 748 KB Output is correct
8 Correct 18 ms 2284 KB Output is correct
9 Correct 52 ms 4332 KB Output is correct
10 Correct 29 ms 2796 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 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 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 12 ms 1136 KB Output is correct
27 Correct 31 ms 2924 KB Output is correct
28 Correct 45 ms 3436 KB Output is correct
29 Correct 97 ms 3052 KB Output is correct
30 Correct 114 ms 3436 KB Output is correct
31 Correct 35 ms 2924 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 23 ms 1644 KB Output is correct
34 Correct 42 ms 3180 KB Output is correct
35 Correct 5 ms 620 KB Output is correct
36 Correct 24 ms 2156 KB Output is correct
37 Correct 34 ms 2412 KB Output is correct
38 Correct 41 ms 3308 KB Output is correct
39 Correct 13 ms 1388 KB Output is correct
40 Correct 2 ms 364 KB Output is correct
41 Correct 126 ms 3948 KB Output is correct
42 Correct 54 ms 4332 KB Output is correct
43 Correct 80 ms 3948 KB Output is correct
44 Correct 55 ms 4204 KB Output is correct
45 Correct 48 ms 4460 KB Output is correct
46 Correct 143 ms 4332 KB Output is correct
47 Correct 47 ms 4076 KB Output is correct
48 Correct 67 ms 4076 KB Output is correct
49 Correct 50 ms 3948 KB Output is correct
50 Correct 513 ms 4076 KB Output is correct
51 Correct 544 ms 4460 KB Output is correct
52 Correct 516 ms 4204 KB Output is correct
53 Correct 534 ms 4716 KB Output is correct
54 Correct 501 ms 4460 KB Output is correct
55 Correct 553 ms 4844 KB Output is correct
56 Correct 508 ms 4204 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 0 ms 364 KB Output is correct
4 Correct 0 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 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 35 ms 2284 KB Output is correct
10 Correct 10 ms 1260 KB Output is correct
11 Correct 21 ms 2412 KB Output is correct
12 Correct 20 ms 2540 KB Output is correct
13 Correct 27 ms 2924 KB Output is correct
14 Correct 18 ms 2156 KB Output is correct
15 Correct 5 ms 748 KB Output is correct
16 Correct 18 ms 2284 KB Output is correct
17 Correct 52 ms 4332 KB Output is correct
18 Correct 29 ms 2796 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 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 364 KB Output is correct
34 Correct 12 ms 1136 KB Output is correct
35 Correct 31 ms 2924 KB Output is correct
36 Correct 45 ms 3436 KB Output is correct
37 Correct 97 ms 3052 KB Output is correct
38 Correct 114 ms 3436 KB Output is correct
39 Correct 35 ms 2924 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 23 ms 1644 KB Output is correct
42 Correct 42 ms 3180 KB Output is correct
43 Correct 5 ms 620 KB Output is correct
44 Correct 24 ms 2156 KB Output is correct
45 Correct 34 ms 2412 KB Output is correct
46 Correct 41 ms 3308 KB Output is correct
47 Correct 13 ms 1388 KB Output is correct
48 Correct 2 ms 364 KB Output is correct
49 Correct 126 ms 3948 KB Output is correct
50 Correct 54 ms 4332 KB Output is correct
51 Correct 80 ms 3948 KB Output is correct
52 Correct 55 ms 4204 KB Output is correct
53 Correct 48 ms 4460 KB Output is correct
54 Correct 143 ms 4332 KB Output is correct
55 Correct 47 ms 4076 KB Output is correct
56 Correct 67 ms 4076 KB Output is correct
57 Correct 50 ms 3948 KB Output is correct
58 Correct 513 ms 4076 KB Output is correct
59 Correct 544 ms 4460 KB Output is correct
60 Correct 516 ms 4204 KB Output is correct
61 Correct 534 ms 4716 KB Output is correct
62 Correct 501 ms 4460 KB Output is correct
63 Correct 553 ms 4844 KB Output is correct
64 Correct 508 ms 4204 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 1 ms 364 KB Output is correct
67 Execution timed out 2041 ms 4844 KB Time limit exceeded
68 Halted 0 ms 0 KB -