Submission #65166

# Submission time Handle Problem Language Result Execution time Memory
65166 2018-08-06T22:59:07 Z kingpig9 Chessboard (IZhO18_chessboard) C++11
47 / 100
2000 ms 51820 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;

//#define debug(...) fprintf(stderr, __VA_ARGS__)
#define debug(...)
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define fillchar(a, s) memset((a), (s), sizeof(a))

template<class T>
void setmin (T &a, T b) {
	if (b < a) {
		a = b;
	}
}

ll N, K, D;
ll X1[MAXN], X2[MAXN], Y1[MAXN], Y2[MAXN];

ll delta (ll xmx, ll ymx) {
	if (xmx == 0 || ymx == 0) {
		return 0;
	}
	debug("xmx = %lld, ymx = %lld\n", xmx, ymx);

	//which one is covered?
	ll xbound = xmx / D, ybound = ymx / D;
	//0 <= x <= xbound, 0 <= y <= ybound -- how many ways x + y is even?
	ll xeven = (xbound + 1) / 2, yeven = (ybound + 1) / 2, xodd = xbound - xeven, yodd = ybound - yeven;
	debug("xeven = %lld, yeven = %lld. xodd = %lld, yodd = %lld.\n", xeven, yeven, xodd, yodd);
	ll ans = (xeven * yeven + xodd * yodd) * D * D;
	debug("ans start out %lld\n", ans);
	
	ll xlen = xmx - xbound * D, ylen = ymx - ybound * D;

	debug("xbound = %lld, ybound = %lld\n", xbound, ybound);
	if (xlen) {
		//one
		//0 <= y < ybound * D
		if (xbound % 2 == 0) {
			//starts with white
			ans += ((ybound + 1) / 2) * (D * xlen);
		} else {
			//starts with black
			ans += (ybound / 2) * (D * xlen);
		}

		//both
		if (ylen) {
			if ((xbound + ybound) % 2 == 0) {
				ans += xlen * ylen;
			}
		}
	}

	if (ylen) {
		if (ybound % 2 == 0) {
			ans += ((xbound + 1) / 2) * (D * ylen);
		} else {
			ans += (xbound / 2) * (D * ylen);
		}
	}

	debug("CHG %lld\n", ans);
	return ans;
}

#warning int overflow!
ll go() {
	debug("----------D = %lld--------------\n", D);
	ll ans = (N / D) * (N / D) / 2 * D * D;
	debug("ANS ASAS %lld\n", ans);
	for (ll i = 0; i < K; i++) {
		ll area = (X2[i] - X1[i]) * (Y2[i] - Y1[i]);
		ll nchange = delta(X1[i], Y1[i]) + delta(X2[i], Y2[i]) - delta(X1[i], Y2[i]) - delta(X2[i], Y1[i]);
		debug("nchange = %lld\n", nchange);
		ans -= (area - nchange);
		ans += nchange;
	}
	debug("D = %lld, we change %lld\n", D, ans);
	return min(ll(N) * N - ans, ans);
}

int main() {
	scanf("%lld %lld", &N, &K);
	for (ll i = 0; i < K; i++) {
		scanf("%lld %lld %lld %lld", &X1[i], &Y1[i], &X2[i], &Y2[i]);
		X1[i]--;
		Y1[i]--;
	}

	ll ans = ll(N) * N;
	for (D = 1; D < N; D++) {
		if (N % D == 0) {
			setmin(ans, go());
		}
	}
	printf("%lld\n", ans);
}

Compilation message

chessboard.cpp:72:2: warning: #warning int overflow! [-Wcpp]
 #warning int overflow!
  ^~~~~~~
chessboard.cpp: In function 'int main()':
chessboard.cpp:89:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld", &N, &K);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
chessboard.cpp:91:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld %lld %lld", &X1[i], &Y1[i], &X2[i], &Y2[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 420 KB Output is correct
4 Correct 2 ms 420 KB Output is correct
5 Correct 3 ms 444 KB Output is correct
6 Correct 4 ms 444 KB Output is correct
7 Correct 2 ms 500 KB Output is correct
8 Correct 2 ms 516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 4132 KB Output is correct
2 Correct 15 ms 4132 KB Output is correct
3 Correct 36 ms 4712 KB Output is correct
4 Correct 34 ms 5840 KB Output is correct
5 Correct 39 ms 7472 KB Output is correct
6 Correct 27 ms 7740 KB Output is correct
7 Correct 8 ms 7740 KB Output is correct
8 Correct 31 ms 8592 KB Output is correct
9 Correct 68 ms 12348 KB Output is correct
10 Correct 38 ms 12348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12348 KB Output is correct
2 Correct 3 ms 12348 KB Output is correct
3 Correct 3 ms 12348 KB Output is correct
4 Correct 5 ms 12348 KB Output is correct
5 Correct 3 ms 12348 KB Output is correct
6 Correct 4 ms 12348 KB Output is correct
7 Correct 6 ms 12348 KB Output is correct
8 Correct 4 ms 12348 KB Output is correct
9 Correct 4 ms 12348 KB Output is correct
10 Correct 2 ms 12348 KB Output is correct
11 Correct 3 ms 12348 KB Output is correct
12 Correct 3 ms 12348 KB Output is correct
13 Correct 4 ms 12348 KB Output is correct
14 Correct 5 ms 12348 KB Output is correct
15 Correct 4 ms 12348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12348 KB Output is correct
2 Correct 3 ms 12348 KB Output is correct
3 Correct 3 ms 12348 KB Output is correct
4 Correct 5 ms 12348 KB Output is correct
5 Correct 3 ms 12348 KB Output is correct
6 Correct 4 ms 12348 KB Output is correct
7 Correct 6 ms 12348 KB Output is correct
8 Correct 4 ms 12348 KB Output is correct
9 Correct 4 ms 12348 KB Output is correct
10 Correct 2 ms 12348 KB Output is correct
11 Correct 3 ms 12348 KB Output is correct
12 Correct 3 ms 12348 KB Output is correct
13 Correct 4 ms 12348 KB Output is correct
14 Correct 5 ms 12348 KB Output is correct
15 Correct 4 ms 12348 KB Output is correct
16 Correct 38 ms 12348 KB Output is correct
17 Correct 54 ms 15500 KB Output is correct
18 Correct 99 ms 17376 KB Output is correct
19 Correct 413 ms 18560 KB Output is correct
20 Correct 480 ms 20600 KB Output is correct
21 Correct 49 ms 21236 KB Output is correct
22 Correct 4 ms 21236 KB Output is correct
23 Correct 68 ms 21236 KB Output is correct
24 Correct 86 ms 23628 KB Output is correct
25 Correct 18 ms 23628 KB Output is correct
26 Correct 58 ms 23688 KB Output is correct
27 Correct 88 ms 25260 KB Output is correct
28 Correct 93 ms 27512 KB Output is correct
29 Correct 27 ms 27512 KB Output is correct
30 Correct 6 ms 27512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 4132 KB Output is correct
2 Correct 15 ms 4132 KB Output is correct
3 Correct 36 ms 4712 KB Output is correct
4 Correct 34 ms 5840 KB Output is correct
5 Correct 39 ms 7472 KB Output is correct
6 Correct 27 ms 7740 KB Output is correct
7 Correct 8 ms 7740 KB Output is correct
8 Correct 31 ms 8592 KB Output is correct
9 Correct 68 ms 12348 KB Output is correct
10 Correct 38 ms 12348 KB Output is correct
11 Correct 3 ms 12348 KB Output is correct
12 Correct 3 ms 12348 KB Output is correct
13 Correct 3 ms 12348 KB Output is correct
14 Correct 5 ms 12348 KB Output is correct
15 Correct 3 ms 12348 KB Output is correct
16 Correct 4 ms 12348 KB Output is correct
17 Correct 6 ms 12348 KB Output is correct
18 Correct 4 ms 12348 KB Output is correct
19 Correct 4 ms 12348 KB Output is correct
20 Correct 2 ms 12348 KB Output is correct
21 Correct 3 ms 12348 KB Output is correct
22 Correct 3 ms 12348 KB Output is correct
23 Correct 4 ms 12348 KB Output is correct
24 Correct 5 ms 12348 KB Output is correct
25 Correct 4 ms 12348 KB Output is correct
26 Correct 38 ms 12348 KB Output is correct
27 Correct 54 ms 15500 KB Output is correct
28 Correct 99 ms 17376 KB Output is correct
29 Correct 413 ms 18560 KB Output is correct
30 Correct 480 ms 20600 KB Output is correct
31 Correct 49 ms 21236 KB Output is correct
32 Correct 4 ms 21236 KB Output is correct
33 Correct 68 ms 21236 KB Output is correct
34 Correct 86 ms 23628 KB Output is correct
35 Correct 18 ms 23628 KB Output is correct
36 Correct 58 ms 23688 KB Output is correct
37 Correct 88 ms 25260 KB Output is correct
38 Correct 93 ms 27512 KB Output is correct
39 Correct 27 ms 27512 KB Output is correct
40 Correct 6 ms 27512 KB Output is correct
41 Correct 355 ms 29820 KB Output is correct
42 Correct 124 ms 32460 KB Output is correct
43 Correct 260 ms 34168 KB Output is correct
44 Correct 110 ms 36672 KB Output is correct
45 Correct 69 ms 39132 KB Output is correct
46 Correct 523 ms 41100 KB Output is correct
47 Correct 59 ms 42936 KB Output is correct
48 Correct 157 ms 45008 KB Output is correct
49 Correct 112 ms 47024 KB Output is correct
50 Correct 1936 ms 49412 KB Output is correct
51 Execution timed out 2070 ms 51820 KB Time limit exceeded
52 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 420 KB Output is correct
4 Correct 2 ms 420 KB Output is correct
5 Correct 3 ms 444 KB Output is correct
6 Correct 4 ms 444 KB Output is correct
7 Correct 2 ms 500 KB Output is correct
8 Correct 2 ms 516 KB Output is correct
9 Correct 45 ms 4132 KB Output is correct
10 Correct 15 ms 4132 KB Output is correct
11 Correct 36 ms 4712 KB Output is correct
12 Correct 34 ms 5840 KB Output is correct
13 Correct 39 ms 7472 KB Output is correct
14 Correct 27 ms 7740 KB Output is correct
15 Correct 8 ms 7740 KB Output is correct
16 Correct 31 ms 8592 KB Output is correct
17 Correct 68 ms 12348 KB Output is correct
18 Correct 38 ms 12348 KB Output is correct
19 Correct 3 ms 12348 KB Output is correct
20 Correct 3 ms 12348 KB Output is correct
21 Correct 3 ms 12348 KB Output is correct
22 Correct 5 ms 12348 KB Output is correct
23 Correct 3 ms 12348 KB Output is correct
24 Correct 4 ms 12348 KB Output is correct
25 Correct 6 ms 12348 KB Output is correct
26 Correct 4 ms 12348 KB Output is correct
27 Correct 4 ms 12348 KB Output is correct
28 Correct 2 ms 12348 KB Output is correct
29 Correct 3 ms 12348 KB Output is correct
30 Correct 3 ms 12348 KB Output is correct
31 Correct 4 ms 12348 KB Output is correct
32 Correct 5 ms 12348 KB Output is correct
33 Correct 4 ms 12348 KB Output is correct
34 Correct 38 ms 12348 KB Output is correct
35 Correct 54 ms 15500 KB Output is correct
36 Correct 99 ms 17376 KB Output is correct
37 Correct 413 ms 18560 KB Output is correct
38 Correct 480 ms 20600 KB Output is correct
39 Correct 49 ms 21236 KB Output is correct
40 Correct 4 ms 21236 KB Output is correct
41 Correct 68 ms 21236 KB Output is correct
42 Correct 86 ms 23628 KB Output is correct
43 Correct 18 ms 23628 KB Output is correct
44 Correct 58 ms 23688 KB Output is correct
45 Correct 88 ms 25260 KB Output is correct
46 Correct 93 ms 27512 KB Output is correct
47 Correct 27 ms 27512 KB Output is correct
48 Correct 6 ms 27512 KB Output is correct
49 Correct 355 ms 29820 KB Output is correct
50 Correct 124 ms 32460 KB Output is correct
51 Correct 260 ms 34168 KB Output is correct
52 Correct 110 ms 36672 KB Output is correct
53 Correct 69 ms 39132 KB Output is correct
54 Correct 523 ms 41100 KB Output is correct
55 Correct 59 ms 42936 KB Output is correct
56 Correct 157 ms 45008 KB Output is correct
57 Correct 112 ms 47024 KB Output is correct
58 Correct 1936 ms 49412 KB Output is correct
59 Execution timed out 2070 ms 51820 KB Time limit exceeded
60 Halted 0 ms 0 KB -