답안 #81947

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
81947 2018-10-28T08:29:39 Z Good Chessboard (IZhO18_chessboard) C++11
70 / 100
1632 ms 4236 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define ff first
#define ss second
#define Maxn 100009
#define ll long long
#define pb push_back
#define Inf 1000000009
#define ppb() pop_back()
#define pii pair <ll , ll>
#define mid(x, y) (x + y) / 2
#define all(x) x.begin(),x.end()
#define llInf 1000000000000000009
#define tr(i, c) for(__typeof(c).begin() i = (c).begin() ; i != (c).end() ; i++)
using namespace std;
using namespace __gnu_pbds;
typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> order;

int n, k;
pii x[Maxn];
pii y[Maxn];
ll ans = llInf;

vector <ll> A;

bool calc (ll x, ll y, ll z) {
	x --, y --;
	return ((x / z) % 2) ^ ((y / z) % 2);
}


int main () {
	//freopen ("file.in", "r", stdin);
	//freopen ("file.out", "w", stdout);
	
 	//srand ((unsigned) time ( NULL ));
	//int randomNumber = rand() % 10 + 1;

	scanf ("%d%d", &n, &k);

	for (int i = 1; i <= k; i++)
		scanf ("%lld%lld%lld%lld", &x[i].ff, &y[i].ff, &x[i].ss, &y[i].ss);	


	for (int i = 1; i < n; i++)
		if (!(n % i))
			A.pb (i);

	for (auto j: A) {
		ll v = j;
		ll u = n / j;
		
		ll sm1[2], sm2[2];
		sm1[0] = sm2[1] = 0;
		
		sm1[1] = (((u * u) + 1) / 2) * v * v;
		sm2[0] = ((u * u) / 2) * v * v;
																
		for (int i = 1; i <= k; i++) {
			ll a = min ((j - (x[i].ff - 1) % j) % j, x[i].ss - x[i].ff + 1);
			ll b = x[i].ss % j;
			ll c = min ((j - (y[i].ff - 1) % j) % j, y[i].ss - y[i].ff + 1);
			ll d = y[i].ss % j;
			
			if (x[i].ff + a > x[i].ss)
				b = 0;
			if (y[i].ff + c > y[i].ss)
				d = 0;	
						
			bool e = calc (x[i].ff, y[i].ff, j);
			sm1[e] += a * c, sm2[e] += a * c;
			
			e = calc (x[i].ff, y[i].ff + c, j);
			ll t = (y[i].ss - y[i].ff - c + 1) / j;
			ll r = (t + 1) / 2 * a * j;
			sm1[e] += r, sm2[e] += r;
			r = t / 2 * a * j;
			sm1[!e] += r, sm2[!e] += r;
			
			e = calc (x[i].ff, y[i].ss, j);
			sm1[e] += a * d, sm2[e] += a * d;
						
			ll xx1 = x[i].ff + a;
			if (xx1 > x[i].ss)
				continue;
			
			e = calc (x[i].ss, y[i].ff, j);
			sm1[e] += b * c, sm2[e] += b * c;
			
			e = calc (x[i].ss, y[i].ff + c, j);
			r = (t + 1) / 2 * b * j;
			sm1[e] += r, sm2[e] += r;
			r = t / 2 * b * j;
			sm1[!e] += r, sm2[!e] += r;
			
			e = calc (x[i].ss, y[i].ss, j);
			sm1[e] += b * d, sm2[e] += b * d;			
			
			ll xx2 = x[i].ss - b;
			if (xx1 > xx2)
				continue;
			
			e = calc (xx1, y[i].ff, j);
			t = (xx2 - xx1 + 1) / j;
			r = (t + 1) / 2 * c * j;
			sm1[e] += r, sm2[e] += r;
			r = t / 2 * c * j;
			sm1[!e] += r, sm2[!e] += r;
			
			ll yy1 = y[i].ff + c;
			if (yy1 > y[i].ss)
				continue;
			
			e = calc (xx1, y[i].ss, j);
			r = (t + 1) / 2 * d * j;
			sm1[e] += r, sm2[e] += r;
			r = t / 2 * d * j;
			sm1[!e] += r, sm2[!e] += r;
			
			ll yy2 = y[i].ss - d;
			if (yy1 > yy2)
				continue;
									
			e = calc (xx1, yy1, j);
			t = (yy2 - yy1 + 1) / j;
			ll t1 = (xx2 - xx1 + 1) / j;
			r = ((t + 1) * (t1 + 1) / 4 + t * t1 / 4) * j * j;
			sm1[e] += r, sm2[e] += r;
			r = (t * (t1 + 1) / 4 + (t + 1) * t1 / 4) * j * j;
			sm1[!e] += r, sm2[!e] += r;
		}
		
		ans = min (ans, min (sm1[1] - sm1[0], sm2[0] - sm2[1]));
	}	

	printf ("%lld\n", ans);
	return 0;
}

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d%d", &n, &k);
  ~~~~~~^~~~~~~~~~~~~~~~
chessboard.cpp:43:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%lld%lld%lld%lld", &x[i].ff, &y[i].ff, &x[i].ss, &y[i].ss); 
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 2 ms 516 KB Output is correct
6 Correct 2 ms 536 KB Output is correct
7 Correct 2 ms 540 KB Output is correct
8 Correct 2 ms 540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 2996 KB Output is correct
2 Correct 14 ms 2996 KB Output is correct
3 Correct 30 ms 2996 KB Output is correct
4 Correct 43 ms 2996 KB Output is correct
5 Correct 43 ms 2996 KB Output is correct
6 Correct 27 ms 2996 KB Output is correct
7 Correct 7 ms 2996 KB Output is correct
8 Correct 27 ms 2996 KB Output is correct
9 Correct 65 ms 3820 KB Output is correct
10 Correct 38 ms 3820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3820 KB Output is correct
2 Correct 3 ms 3820 KB Output is correct
3 Correct 2 ms 3820 KB Output is correct
4 Correct 3 ms 3820 KB Output is correct
5 Correct 3 ms 3820 KB Output is correct
6 Correct 2 ms 3820 KB Output is correct
7 Correct 4 ms 3820 KB Output is correct
8 Correct 3 ms 3820 KB Output is correct
9 Correct 2 ms 3820 KB Output is correct
10 Correct 2 ms 3820 KB Output is correct
11 Correct 3 ms 3820 KB Output is correct
12 Correct 2 ms 3820 KB Output is correct
13 Correct 3 ms 3820 KB Output is correct
14 Correct 3 ms 3820 KB Output is correct
15 Correct 4 ms 3820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3820 KB Output is correct
2 Correct 3 ms 3820 KB Output is correct
3 Correct 2 ms 3820 KB Output is correct
4 Correct 3 ms 3820 KB Output is correct
5 Correct 3 ms 3820 KB Output is correct
6 Correct 2 ms 3820 KB Output is correct
7 Correct 4 ms 3820 KB Output is correct
8 Correct 3 ms 3820 KB Output is correct
9 Correct 2 ms 3820 KB Output is correct
10 Correct 2 ms 3820 KB Output is correct
11 Correct 3 ms 3820 KB Output is correct
12 Correct 2 ms 3820 KB Output is correct
13 Correct 3 ms 3820 KB Output is correct
14 Correct 3 ms 3820 KB Output is correct
15 Correct 4 ms 3820 KB Output is correct
16 Correct 27 ms 3820 KB Output is correct
17 Correct 58 ms 3820 KB Output is correct
18 Correct 90 ms 4236 KB Output is correct
19 Correct 332 ms 4236 KB Output is correct
20 Correct 366 ms 4236 KB Output is correct
21 Correct 55 ms 4236 KB Output is correct
22 Correct 3 ms 4236 KB Output is correct
23 Correct 63 ms 4236 KB Output is correct
24 Correct 84 ms 4236 KB Output is correct
25 Correct 14 ms 4236 KB Output is correct
26 Correct 63 ms 4236 KB Output is correct
27 Correct 80 ms 4236 KB Output is correct
28 Correct 87 ms 4236 KB Output is correct
29 Correct 24 ms 4236 KB Output is correct
30 Correct 4 ms 4236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 2996 KB Output is correct
2 Correct 14 ms 2996 KB Output is correct
3 Correct 30 ms 2996 KB Output is correct
4 Correct 43 ms 2996 KB Output is correct
5 Correct 43 ms 2996 KB Output is correct
6 Correct 27 ms 2996 KB Output is correct
7 Correct 7 ms 2996 KB Output is correct
8 Correct 27 ms 2996 KB Output is correct
9 Correct 65 ms 3820 KB Output is correct
10 Correct 38 ms 3820 KB Output is correct
11 Correct 2 ms 3820 KB Output is correct
12 Correct 3 ms 3820 KB Output is correct
13 Correct 2 ms 3820 KB Output is correct
14 Correct 3 ms 3820 KB Output is correct
15 Correct 3 ms 3820 KB Output is correct
16 Correct 2 ms 3820 KB Output is correct
17 Correct 4 ms 3820 KB Output is correct
18 Correct 3 ms 3820 KB Output is correct
19 Correct 2 ms 3820 KB Output is correct
20 Correct 2 ms 3820 KB Output is correct
21 Correct 3 ms 3820 KB Output is correct
22 Correct 2 ms 3820 KB Output is correct
23 Correct 3 ms 3820 KB Output is correct
24 Correct 3 ms 3820 KB Output is correct
25 Correct 4 ms 3820 KB Output is correct
26 Correct 27 ms 3820 KB Output is correct
27 Correct 58 ms 3820 KB Output is correct
28 Correct 90 ms 4236 KB Output is correct
29 Correct 332 ms 4236 KB Output is correct
30 Correct 366 ms 4236 KB Output is correct
31 Correct 55 ms 4236 KB Output is correct
32 Correct 3 ms 4236 KB Output is correct
33 Correct 63 ms 4236 KB Output is correct
34 Correct 84 ms 4236 KB Output is correct
35 Correct 14 ms 4236 KB Output is correct
36 Correct 63 ms 4236 KB Output is correct
37 Correct 80 ms 4236 KB Output is correct
38 Correct 87 ms 4236 KB Output is correct
39 Correct 24 ms 4236 KB Output is correct
40 Correct 4 ms 4236 KB Output is correct
41 Correct 274 ms 4236 KB Output is correct
42 Correct 110 ms 4236 KB Output is correct
43 Correct 165 ms 4236 KB Output is correct
44 Correct 96 ms 4236 KB Output is correct
45 Correct 73 ms 4236 KB Output is correct
46 Correct 299 ms 4236 KB Output is correct
47 Correct 69 ms 4236 KB Output is correct
48 Correct 127 ms 4236 KB Output is correct
49 Correct 85 ms 4236 KB Output is correct
50 Correct 1366 ms 4236 KB Output is correct
51 Correct 1444 ms 4236 KB Output is correct
52 Correct 1354 ms 4236 KB Output is correct
53 Correct 1442 ms 4236 KB Output is correct
54 Correct 1336 ms 4236 KB Output is correct
55 Correct 1505 ms 4236 KB Output is correct
56 Correct 1338 ms 4236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 2 ms 516 KB Output is correct
6 Correct 2 ms 536 KB Output is correct
7 Correct 2 ms 540 KB Output is correct
8 Correct 2 ms 540 KB Output is correct
9 Correct 54 ms 2996 KB Output is correct
10 Correct 14 ms 2996 KB Output is correct
11 Correct 30 ms 2996 KB Output is correct
12 Correct 43 ms 2996 KB Output is correct
13 Correct 43 ms 2996 KB Output is correct
14 Correct 27 ms 2996 KB Output is correct
15 Correct 7 ms 2996 KB Output is correct
16 Correct 27 ms 2996 KB Output is correct
17 Correct 65 ms 3820 KB Output is correct
18 Correct 38 ms 3820 KB Output is correct
19 Correct 2 ms 3820 KB Output is correct
20 Correct 3 ms 3820 KB Output is correct
21 Correct 2 ms 3820 KB Output is correct
22 Correct 3 ms 3820 KB Output is correct
23 Correct 3 ms 3820 KB Output is correct
24 Correct 2 ms 3820 KB Output is correct
25 Correct 4 ms 3820 KB Output is correct
26 Correct 3 ms 3820 KB Output is correct
27 Correct 2 ms 3820 KB Output is correct
28 Correct 2 ms 3820 KB Output is correct
29 Correct 3 ms 3820 KB Output is correct
30 Correct 2 ms 3820 KB Output is correct
31 Correct 3 ms 3820 KB Output is correct
32 Correct 3 ms 3820 KB Output is correct
33 Correct 4 ms 3820 KB Output is correct
34 Correct 27 ms 3820 KB Output is correct
35 Correct 58 ms 3820 KB Output is correct
36 Correct 90 ms 4236 KB Output is correct
37 Correct 332 ms 4236 KB Output is correct
38 Correct 366 ms 4236 KB Output is correct
39 Correct 55 ms 4236 KB Output is correct
40 Correct 3 ms 4236 KB Output is correct
41 Correct 63 ms 4236 KB Output is correct
42 Correct 84 ms 4236 KB Output is correct
43 Correct 14 ms 4236 KB Output is correct
44 Correct 63 ms 4236 KB Output is correct
45 Correct 80 ms 4236 KB Output is correct
46 Correct 87 ms 4236 KB Output is correct
47 Correct 24 ms 4236 KB Output is correct
48 Correct 4 ms 4236 KB Output is correct
49 Correct 274 ms 4236 KB Output is correct
50 Correct 110 ms 4236 KB Output is correct
51 Correct 165 ms 4236 KB Output is correct
52 Correct 96 ms 4236 KB Output is correct
53 Correct 73 ms 4236 KB Output is correct
54 Correct 299 ms 4236 KB Output is correct
55 Correct 69 ms 4236 KB Output is correct
56 Correct 127 ms 4236 KB Output is correct
57 Correct 85 ms 4236 KB Output is correct
58 Correct 1366 ms 4236 KB Output is correct
59 Correct 1444 ms 4236 KB Output is correct
60 Correct 1354 ms 4236 KB Output is correct
61 Correct 1442 ms 4236 KB Output is correct
62 Correct 1336 ms 4236 KB Output is correct
63 Correct 1505 ms 4236 KB Output is correct
64 Correct 1338 ms 4236 KB Output is correct
65 Correct 2 ms 4236 KB Output is correct
66 Correct 2 ms 4236 KB Output is correct
67 Correct 1491 ms 4236 KB Output is correct
68 Correct 1632 ms 4236 KB Output is correct
69 Correct 1330 ms 4236 KB Output is correct
70 Correct 1447 ms 4236 KB Output is correct
71 Correct 1384 ms 4236 KB Output is correct
72 Correct 1410 ms 4236 KB Output is correct
73 Correct 1391 ms 4236 KB Output is correct
74 Correct 1505 ms 4236 KB Output is correct
75 Correct 1415 ms 4236 KB Output is correct
76 Correct 1505 ms 4236 KB Output is correct
77 Correct 252 ms 4236 KB Output is correct
78 Incorrect 93 ms 4236 KB Output isn't correct
79 Halted 0 ms 0 KB -