답안 #907439

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
907439 2024-01-15T14:53:27 Z daoquanglinh2007 Chessboard (IZhO18_chessboard) C++17
100 / 100
336 ms 5960 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)*(v[i]-y[i]+1));
			update(blu, bly, blu, bly, (u[i]-(blu-1)*t)*(v[i]-y[i]+1));
			update(blx+1, bly, blu-1, bly, t*(v[i]-y[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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 500 KB Output is correct
5 Correct 0 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 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 3164 KB Output is correct
2 Correct 5 ms 2780 KB Output is correct
3 Correct 11 ms 2912 KB Output is correct
4 Correct 11 ms 2824 KB Output is correct
5 Correct 14 ms 2904 KB Output is correct
6 Correct 10 ms 2908 KB Output is correct
7 Correct 3 ms 2396 KB Output is correct
8 Correct 12 ms 2908 KB Output is correct
9 Correct 24 ms 3444 KB Output is correct
10 Correct 14 ms 2968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 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 2392 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 2392 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 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 2392 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 2392 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 2904 KB Output is correct
17 Correct 18 ms 3164 KB Output is correct
18 Correct 26 ms 3536 KB Output is correct
19 Correct 63 ms 3388 KB Output is correct
20 Correct 70 ms 3420 KB Output is correct
21 Correct 18 ms 3164 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 14 ms 2904 KB Output is correct
24 Correct 23 ms 3416 KB Output is correct
25 Correct 3 ms 2396 KB Output is correct
26 Correct 16 ms 3012 KB Output is correct
27 Correct 21 ms 3160 KB Output is correct
28 Correct 24 ms 3416 KB Output is correct
29 Correct 9 ms 2908 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 3164 KB Output is correct
2 Correct 5 ms 2780 KB Output is correct
3 Correct 11 ms 2912 KB Output is correct
4 Correct 11 ms 2824 KB Output is correct
5 Correct 14 ms 2904 KB Output is correct
6 Correct 10 ms 2908 KB Output is correct
7 Correct 3 ms 2396 KB Output is correct
8 Correct 12 ms 2908 KB Output is correct
9 Correct 24 ms 3444 KB Output is correct
10 Correct 14 ms 2968 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 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 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 2392 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 2904 KB Output is correct
27 Correct 18 ms 3164 KB Output is correct
28 Correct 26 ms 3536 KB Output is correct
29 Correct 63 ms 3388 KB Output is correct
30 Correct 70 ms 3420 KB Output is correct
31 Correct 18 ms 3164 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 14 ms 2904 KB Output is correct
34 Correct 23 ms 3416 KB Output is correct
35 Correct 3 ms 2396 KB Output is correct
36 Correct 16 ms 3012 KB Output is correct
37 Correct 21 ms 3160 KB Output is correct
38 Correct 24 ms 3416 KB Output is correct
39 Correct 9 ms 2908 KB Output is correct
40 Correct 2 ms 2396 KB Output is correct
41 Correct 60 ms 3324 KB Output is correct
42 Correct 28 ms 3420 KB Output is correct
43 Correct 41 ms 3164 KB Output is correct
44 Correct 27 ms 3416 KB Output is correct
45 Correct 25 ms 3420 KB Output is correct
46 Correct 67 ms 3460 KB Output is correct
47 Correct 22 ms 3160 KB Output is correct
48 Correct 35 ms 3160 KB Output is correct
49 Correct 25 ms 3164 KB Output is correct
50 Correct 264 ms 3432 KB Output is correct
51 Correct 281 ms 3420 KB Output is correct
52 Correct 266 ms 3664 KB Output is correct
53 Correct 279 ms 3516 KB Output is correct
54 Correct 258 ms 3400 KB Output is correct
55 Correct 289 ms 3420 KB Output is correct
56 Correct 250 ms 3356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 500 KB Output is correct
5 Correct 0 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 0 ms 348 KB Output is correct
9 Correct 16 ms 3164 KB Output is correct
10 Correct 5 ms 2780 KB Output is correct
11 Correct 11 ms 2912 KB Output is correct
12 Correct 11 ms 2824 KB Output is correct
13 Correct 14 ms 2904 KB Output is correct
14 Correct 10 ms 2908 KB Output is correct
15 Correct 3 ms 2396 KB Output is correct
16 Correct 12 ms 2908 KB Output is correct
17 Correct 24 ms 3444 KB Output is correct
18 Correct 14 ms 2968 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 2392 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2392 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 2392 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 2904 KB Output is correct
35 Correct 18 ms 3164 KB Output is correct
36 Correct 26 ms 3536 KB Output is correct
37 Correct 63 ms 3388 KB Output is correct
38 Correct 70 ms 3420 KB Output is correct
39 Correct 18 ms 3164 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 14 ms 2904 KB Output is correct
42 Correct 23 ms 3416 KB Output is correct
43 Correct 3 ms 2396 KB Output is correct
44 Correct 16 ms 3012 KB Output is correct
45 Correct 21 ms 3160 KB Output is correct
46 Correct 24 ms 3416 KB Output is correct
47 Correct 9 ms 2908 KB Output is correct
48 Correct 2 ms 2396 KB Output is correct
49 Correct 60 ms 3324 KB Output is correct
50 Correct 28 ms 3420 KB Output is correct
51 Correct 41 ms 3164 KB Output is correct
52 Correct 27 ms 3416 KB Output is correct
53 Correct 25 ms 3420 KB Output is correct
54 Correct 67 ms 3460 KB Output is correct
55 Correct 22 ms 3160 KB Output is correct
56 Correct 35 ms 3160 KB Output is correct
57 Correct 25 ms 3164 KB Output is correct
58 Correct 264 ms 3432 KB Output is correct
59 Correct 281 ms 3420 KB Output is correct
60 Correct 266 ms 3664 KB Output is correct
61 Correct 279 ms 3516 KB Output is correct
62 Correct 258 ms 3400 KB Output is correct
63 Correct 289 ms 3420 KB Output is correct
64 Correct 250 ms 3356 KB Output is correct
65 Correct 1 ms 2392 KB Output is correct
66 Correct 1 ms 2648 KB Output is correct
67 Correct 318 ms 3412 KB Output is correct
68 Correct 316 ms 5684 KB Output is correct
69 Correct 271 ms 5268 KB Output is correct
70 Correct 296 ms 5456 KB Output is correct
71 Correct 301 ms 5460 KB Output is correct
72 Correct 291 ms 5464 KB Output is correct
73 Correct 289 ms 5212 KB Output is correct
74 Correct 311 ms 5424 KB Output is correct
75 Correct 299 ms 5504 KB Output is correct
76 Correct 319 ms 5600 KB Output is correct
77 Correct 64 ms 5724 KB Output is correct
78 Correct 30 ms 5456 KB Output is correct
79 Correct 45 ms 5368 KB Output is correct
80 Correct 48 ms 5464 KB Output is correct
81 Correct 45 ms 5200 KB Output is correct
82 Correct 40 ms 5456 KB Output is correct
83 Correct 35 ms 5212 KB Output is correct
84 Correct 196 ms 5836 KB Output is correct
85 Correct 335 ms 5712 KB Output is correct
86 Correct 1 ms 2508 KB Output is correct
87 Correct 1 ms 2392 KB Output is correct
88 Correct 336 ms 5960 KB Output is correct
89 Correct 67 ms 3164 KB Output is correct
90 Correct 1 ms 2392 KB Output is correct