Submission #907428

# Submission time Handle Problem Language Result Execution time Memory
907428 2024-01-15T14:20:47 Z daoquanglinh2007 Chessboard (IZhO18_chessboard) C++17
70 / 100
314 ms 5836 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int NM = 1e5, inf = 1e18;

int N, K, x[NM+5], y[NM+5], u[NM+5], v[NM+5], ans = +inf;
int num[2];

void update(int lx, int ly, int rx, int ry, int c){
	if (lx > rx) return;
	if (ly > ry) return;
	int tmp = (rx-lx+1)*(ry-ly+1);
	num[(lx+ly)&1] += (tmp+1)/2 * c;
	num[!((lx+ly)&1)] += tmp/2 * c;
}

void solve(int t){
	num[0] = num[1] = 0;
	for (int i = 1; i <= K; i++){
		int blx = x[i]/t+(x[i]%t > 0), bly = y[i]/t+(y[i]%t > 0), blu = u[i]/t+(u[i]%t > 0), blv = v[i]/t+(v[i]%t > 0);
		if (blx == blu && bly == blv) update(blx, bly, blx, bly, (u[i]-x[i]+1)*(v[i]-y[i]+1));
		else if (blx == blu){
			update(blx, bly, blx, bly, (u[i]-x[i]+1)*(bly*t-y[i]+1));
			update(blx, blv, blx, blv, (u[i]-x[i]+1)*(v[i]-(blv-1)*t));
			update(blx, bly+1, blx, blv-1, (u[i]-x[i]+1)*t);
		}
		else if (bly == blv){
			update(blx, bly, blx, bly, (blx*t-x[i]+1)*(y[i]-v[i]+1));
			update(blu, bly, blu, bly, (u[i]-(blu-1)*t)*(y[i]-v[i]+1));
			update(blx+1, bly, blu-1, blv, t*(y[i]-v[i]+1));
		}
		else{
			update(blx, bly, blx, bly, (blx*t-x[i]+1)*(bly*t-y[i]+1));
			update(blx, blv, blx, blv, (blx*t-x[i]+1)*(v[i]-(blv-1)*t));
			update(blu, bly, blu, bly, (u[i]-(blu-1)*t)*(bly*t-y[i]+1));
			update(blu, blv, blu, blv, (u[i]-(blu-1)*t)*(v[i]-(blv-1)*t));
			
			update(blx, bly+1, blx, blv-1, (blx*t-x[i]+1)*t);
			update(blx+1, bly, blu-1, bly, t*(bly*t-y[i]+1));
			update(blu, bly+1, blu, blv-1, (u[i]-(blu-1)*t)*t);
			update(blx+1, blv, blu-1, blv, t*(v[i]-(blv-1)*t));
			
			update(blx+1, bly+1, blu-1, blv-1, t*t);
		}
	}
	int targ = t*t*(N*N/(t*t)/2);
	ans = min(ans, abs(targ-num[1])+num[0]);
	ans = min(ans, abs(N*N-targ-num[0])+num[1]);
}

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin >> N >> K;
	for (int i = 1; i <= K; i++){
		cin >> x[i] >> y[i] >> u[i] >> v[i];
	}
	for (int i = 1; i*i <= N; i++)
		if (N%i == 0){
			solve(i);
			if (i > 1) solve(N/i);
		}
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 4492 KB Output is correct
2 Correct 6 ms 2908 KB Output is correct
3 Correct 11 ms 3932 KB Output is correct
4 Correct 13 ms 3896 KB Output is correct
5 Correct 16 ms 4188 KB Output is correct
6 Correct 10 ms 3676 KB Output is correct
7 Correct 3 ms 2652 KB Output is correct
8 Correct 12 ms 3676 KB Output is correct
9 Correct 24 ms 5280 KB Output is correct
10 Correct 14 ms 4028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 8 ms 3164 KB Output is correct
17 Correct 21 ms 4668 KB Output is correct
18 Correct 27 ms 5204 KB Output is correct
19 Correct 64 ms 4700 KB Output is correct
20 Correct 73 ms 4956 KB Output is correct
21 Correct 18 ms 4444 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 15 ms 3676 KB Output is correct
24 Correct 24 ms 4700 KB Output is correct
25 Correct 4 ms 2784 KB Output is correct
26 Correct 16 ms 3932 KB Output is correct
27 Correct 21 ms 4188 KB Output is correct
28 Correct 25 ms 5036 KB Output is correct
29 Correct 8 ms 3420 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 4492 KB Output is correct
2 Correct 6 ms 2908 KB Output is correct
3 Correct 11 ms 3932 KB Output is correct
4 Correct 13 ms 3896 KB Output is correct
5 Correct 16 ms 4188 KB Output is correct
6 Correct 10 ms 3676 KB Output is correct
7 Correct 3 ms 2652 KB Output is correct
8 Correct 12 ms 3676 KB Output is correct
9 Correct 24 ms 5280 KB Output is correct
10 Correct 14 ms 4028 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 8 ms 3164 KB Output is correct
27 Correct 21 ms 4668 KB Output is correct
28 Correct 27 ms 5204 KB Output is correct
29 Correct 64 ms 4700 KB Output is correct
30 Correct 73 ms 4956 KB Output is correct
31 Correct 18 ms 4444 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 15 ms 3676 KB Output is correct
34 Correct 24 ms 4700 KB Output is correct
35 Correct 4 ms 2784 KB Output is correct
36 Correct 16 ms 3932 KB Output is correct
37 Correct 21 ms 4188 KB Output is correct
38 Correct 25 ms 5036 KB Output is correct
39 Correct 8 ms 3420 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 62 ms 5204 KB Output is correct
42 Correct 40 ms 5836 KB Output is correct
43 Correct 40 ms 5200 KB Output is correct
44 Correct 29 ms 5464 KB Output is correct
45 Correct 26 ms 5724 KB Output is correct
46 Correct 68 ms 5464 KB Output is correct
47 Correct 23 ms 5204 KB Output is correct
48 Correct 34 ms 5452 KB Output is correct
49 Correct 26 ms 5212 KB Output is correct
50 Correct 264 ms 5596 KB Output is correct
51 Correct 285 ms 5712 KB Output is correct
52 Correct 262 ms 5572 KB Output is correct
53 Correct 280 ms 5804 KB Output is correct
54 Correct 259 ms 5716 KB Output is correct
55 Correct 290 ms 5716 KB Output is correct
56 Correct 256 ms 5420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 17 ms 4492 KB Output is correct
10 Correct 6 ms 2908 KB Output is correct
11 Correct 11 ms 3932 KB Output is correct
12 Correct 13 ms 3896 KB Output is correct
13 Correct 16 ms 4188 KB Output is correct
14 Correct 10 ms 3676 KB Output is correct
15 Correct 3 ms 2652 KB Output is correct
16 Correct 12 ms 3676 KB Output is correct
17 Correct 24 ms 5280 KB Output is correct
18 Correct 14 ms 4028 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 8 ms 3164 KB Output is correct
35 Correct 21 ms 4668 KB Output is correct
36 Correct 27 ms 5204 KB Output is correct
37 Correct 64 ms 4700 KB Output is correct
38 Correct 73 ms 4956 KB Output is correct
39 Correct 18 ms 4444 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 15 ms 3676 KB Output is correct
42 Correct 24 ms 4700 KB Output is correct
43 Correct 4 ms 2784 KB Output is correct
44 Correct 16 ms 3932 KB Output is correct
45 Correct 21 ms 4188 KB Output is correct
46 Correct 25 ms 5036 KB Output is correct
47 Correct 8 ms 3420 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 62 ms 5204 KB Output is correct
50 Correct 40 ms 5836 KB Output is correct
51 Correct 40 ms 5200 KB Output is correct
52 Correct 29 ms 5464 KB Output is correct
53 Correct 26 ms 5724 KB Output is correct
54 Correct 68 ms 5464 KB Output is correct
55 Correct 23 ms 5204 KB Output is correct
56 Correct 34 ms 5452 KB Output is correct
57 Correct 26 ms 5212 KB Output is correct
58 Correct 264 ms 5596 KB Output is correct
59 Correct 285 ms 5712 KB Output is correct
60 Correct 262 ms 5572 KB Output is correct
61 Correct 280 ms 5804 KB Output is correct
62 Correct 259 ms 5716 KB Output is correct
63 Correct 290 ms 5716 KB Output is correct
64 Correct 256 ms 5420 KB Output is correct
65 Correct 1 ms 2396 KB Output is correct
66 Correct 1 ms 2396 KB Output is correct
67 Incorrect 314 ms 5708 KB Output isn't correct
68 Halted 0 ms 0 KB -