Submission #65170

# Submission time Handle Problem Language Result Execution time Memory
65170 2018-08-06T23:10:21 Z kingpig9 Chessboard (IZhO18_chessboard) C++11
47 / 100
2000 ms 3836 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, D;
ll dsqr;
int K;
ll X1[MAXN], X2[MAXN], Y1[MAXN], Y2[MAXN];
ll totrect;

ll delta (ll xmx, ll ymx) {
	if (xmx == 0 || ymx == 0) {
		return 0;
	}

	//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 xodd = xbound >> 1, yodd = ybound >> 1, xeven = xbound - xodd, yeven = ybound - yodd;
	ll ans = (xeven * yeven + xodd * yodd) * dsqr;
	
	ll xlen = xmx - xbound * D, ylen = ymx - ybound * D;

	if (xlen) {
		//one
		//0 <= y < ybound * D
		ans += ((xbound & 1) ? yodd : yeven) * D * xlen;

		//both
		if (ylen) {
			if ((xbound & 1) == (ybound & 1)) {
				ans += xlen * ylen;
			}
		}
	}

	if (ylen) {
		ans += ((ybound & 1) ? xodd : xeven) * D * ylen;
	}

	return ans;
}

ll go() {
	dsqr = D * D;

	ll ans = dsqr * (((N / D) * (N / D)) >> 1) - totrect;
	for (int i = 0; i < K; i++) {
		ans += (delta(X1[i], Y1[i]) + delta(X2[i], Y2[i]) - delta(X1[i], Y2[i]) - delta(X2[i], Y1[i])) << 1;
	}
	return min(N * N - ans, ans);
}

int main() {
	scanf("%lld %d", &N, &K);
	for (int i = 0; i < K; i++) {
		scanf("%lld %lld %lld %lld", &X1[i], &Y1[i], &X2[i], &Y2[i]);
		X1[i]--;
		Y1[i]--;
		totrect += (X2[i] - X1[i]) * (Y2[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: In function 'int main()':
chessboard.cpp:71:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %d", &N, &K);
  ~~~~~^~~~~~~~~~~~~~~~~~~
chessboard.cpp:73: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 252 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 2 ms 464 KB Output is correct
5 Correct 2 ms 668 KB Output is correct
6 Correct 2 ms 668 KB Output is correct
7 Correct 3 ms 668 KB Output is correct
8 Correct 2 ms 668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 2540 KB Output is correct
2 Correct 14 ms 2540 KB Output is correct
3 Correct 41 ms 2540 KB Output is correct
4 Correct 30 ms 2540 KB Output is correct
5 Correct 52 ms 2540 KB Output is correct
6 Correct 31 ms 2540 KB Output is correct
7 Correct 8 ms 2540 KB Output is correct
8 Correct 26 ms 2540 KB Output is correct
9 Correct 80 ms 3464 KB Output is correct
10 Correct 36 ms 3464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3464 KB Output is correct
2 Correct 2 ms 3464 KB Output is correct
3 Correct 2 ms 3464 KB Output is correct
4 Correct 4 ms 3464 KB Output is correct
5 Correct 3 ms 3464 KB Output is correct
6 Correct 3 ms 3464 KB Output is correct
7 Correct 3 ms 3464 KB Output is correct
8 Correct 4 ms 3464 KB Output is correct
9 Correct 3 ms 3464 KB Output is correct
10 Correct 2 ms 3464 KB Output is correct
11 Correct 3 ms 3464 KB Output is correct
12 Correct 2 ms 3464 KB Output is correct
13 Correct 4 ms 3464 KB Output is correct
14 Correct 3 ms 3464 KB Output is correct
15 Correct 3 ms 3464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3464 KB Output is correct
2 Correct 2 ms 3464 KB Output is correct
3 Correct 2 ms 3464 KB Output is correct
4 Correct 4 ms 3464 KB Output is correct
5 Correct 3 ms 3464 KB Output is correct
6 Correct 3 ms 3464 KB Output is correct
7 Correct 3 ms 3464 KB Output is correct
8 Correct 4 ms 3464 KB Output is correct
9 Correct 3 ms 3464 KB Output is correct
10 Correct 2 ms 3464 KB Output is correct
11 Correct 3 ms 3464 KB Output is correct
12 Correct 2 ms 3464 KB Output is correct
13 Correct 4 ms 3464 KB Output is correct
14 Correct 3 ms 3464 KB Output is correct
15 Correct 3 ms 3464 KB Output is correct
16 Correct 27 ms 3464 KB Output is correct
17 Correct 57 ms 3464 KB Output is correct
18 Correct 95 ms 3728 KB Output is correct
19 Correct 418 ms 3728 KB Output is correct
20 Correct 486 ms 3836 KB Output is correct
21 Correct 51 ms 3836 KB Output is correct
22 Correct 4 ms 3836 KB Output is correct
23 Correct 73 ms 3836 KB Output is correct
24 Correct 87 ms 3836 KB Output is correct
25 Correct 17 ms 3836 KB Output is correct
26 Correct 60 ms 3836 KB Output is correct
27 Correct 86 ms 3836 KB Output is correct
28 Correct 100 ms 3836 KB Output is correct
29 Correct 23 ms 3836 KB Output is correct
30 Correct 5 ms 3836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 2540 KB Output is correct
2 Correct 14 ms 2540 KB Output is correct
3 Correct 41 ms 2540 KB Output is correct
4 Correct 30 ms 2540 KB Output is correct
5 Correct 52 ms 2540 KB Output is correct
6 Correct 31 ms 2540 KB Output is correct
7 Correct 8 ms 2540 KB Output is correct
8 Correct 26 ms 2540 KB Output is correct
9 Correct 80 ms 3464 KB Output is correct
10 Correct 36 ms 3464 KB Output is correct
11 Correct 2 ms 3464 KB Output is correct
12 Correct 2 ms 3464 KB Output is correct
13 Correct 2 ms 3464 KB Output is correct
14 Correct 4 ms 3464 KB Output is correct
15 Correct 3 ms 3464 KB Output is correct
16 Correct 3 ms 3464 KB Output is correct
17 Correct 3 ms 3464 KB Output is correct
18 Correct 4 ms 3464 KB Output is correct
19 Correct 3 ms 3464 KB Output is correct
20 Correct 2 ms 3464 KB Output is correct
21 Correct 3 ms 3464 KB Output is correct
22 Correct 2 ms 3464 KB Output is correct
23 Correct 4 ms 3464 KB Output is correct
24 Correct 3 ms 3464 KB Output is correct
25 Correct 3 ms 3464 KB Output is correct
26 Correct 27 ms 3464 KB Output is correct
27 Correct 57 ms 3464 KB Output is correct
28 Correct 95 ms 3728 KB Output is correct
29 Correct 418 ms 3728 KB Output is correct
30 Correct 486 ms 3836 KB Output is correct
31 Correct 51 ms 3836 KB Output is correct
32 Correct 4 ms 3836 KB Output is correct
33 Correct 73 ms 3836 KB Output is correct
34 Correct 87 ms 3836 KB Output is correct
35 Correct 17 ms 3836 KB Output is correct
36 Correct 60 ms 3836 KB Output is correct
37 Correct 86 ms 3836 KB Output is correct
38 Correct 100 ms 3836 KB Output is correct
39 Correct 23 ms 3836 KB Output is correct
40 Correct 5 ms 3836 KB Output is correct
41 Correct 351 ms 3836 KB Output is correct
42 Correct 119 ms 3836 KB Output is correct
43 Correct 217 ms 3836 KB Output is correct
44 Correct 123 ms 3836 KB Output is correct
45 Correct 85 ms 3836 KB Output is correct
46 Correct 370 ms 3836 KB Output is correct
47 Correct 63 ms 3836 KB Output is correct
48 Correct 154 ms 3836 KB Output is correct
49 Correct 85 ms 3836 KB Output is correct
50 Correct 1850 ms 3836 KB Output is correct
51 Execution timed out 2025 ms 3836 KB Time limit exceeded
52 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 252 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 2 ms 464 KB Output is correct
5 Correct 2 ms 668 KB Output is correct
6 Correct 2 ms 668 KB Output is correct
7 Correct 3 ms 668 KB Output is correct
8 Correct 2 ms 668 KB Output is correct
9 Correct 44 ms 2540 KB Output is correct
10 Correct 14 ms 2540 KB Output is correct
11 Correct 41 ms 2540 KB Output is correct
12 Correct 30 ms 2540 KB Output is correct
13 Correct 52 ms 2540 KB Output is correct
14 Correct 31 ms 2540 KB Output is correct
15 Correct 8 ms 2540 KB Output is correct
16 Correct 26 ms 2540 KB Output is correct
17 Correct 80 ms 3464 KB Output is correct
18 Correct 36 ms 3464 KB Output is correct
19 Correct 2 ms 3464 KB Output is correct
20 Correct 2 ms 3464 KB Output is correct
21 Correct 2 ms 3464 KB Output is correct
22 Correct 4 ms 3464 KB Output is correct
23 Correct 3 ms 3464 KB Output is correct
24 Correct 3 ms 3464 KB Output is correct
25 Correct 3 ms 3464 KB Output is correct
26 Correct 4 ms 3464 KB Output is correct
27 Correct 3 ms 3464 KB Output is correct
28 Correct 2 ms 3464 KB Output is correct
29 Correct 3 ms 3464 KB Output is correct
30 Correct 2 ms 3464 KB Output is correct
31 Correct 4 ms 3464 KB Output is correct
32 Correct 3 ms 3464 KB Output is correct
33 Correct 3 ms 3464 KB Output is correct
34 Correct 27 ms 3464 KB Output is correct
35 Correct 57 ms 3464 KB Output is correct
36 Correct 95 ms 3728 KB Output is correct
37 Correct 418 ms 3728 KB Output is correct
38 Correct 486 ms 3836 KB Output is correct
39 Correct 51 ms 3836 KB Output is correct
40 Correct 4 ms 3836 KB Output is correct
41 Correct 73 ms 3836 KB Output is correct
42 Correct 87 ms 3836 KB Output is correct
43 Correct 17 ms 3836 KB Output is correct
44 Correct 60 ms 3836 KB Output is correct
45 Correct 86 ms 3836 KB Output is correct
46 Correct 100 ms 3836 KB Output is correct
47 Correct 23 ms 3836 KB Output is correct
48 Correct 5 ms 3836 KB Output is correct
49 Correct 351 ms 3836 KB Output is correct
50 Correct 119 ms 3836 KB Output is correct
51 Correct 217 ms 3836 KB Output is correct
52 Correct 123 ms 3836 KB Output is correct
53 Correct 85 ms 3836 KB Output is correct
54 Correct 370 ms 3836 KB Output is correct
55 Correct 63 ms 3836 KB Output is correct
56 Correct 154 ms 3836 KB Output is correct
57 Correct 85 ms 3836 KB Output is correct
58 Correct 1850 ms 3836 KB Output is correct
59 Execution timed out 2025 ms 3836 KB Time limit exceeded
60 Halted 0 ms 0 KB -