답안 #89271

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
89271 2018-12-11T08:13:22 Z dimash241 Chessboard (IZhO18_chessboard) C++17
70 / 100
1612 ms 39544 KB
# include <stdio.h>
# include <bits/stdc++.h>


#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (int i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (int i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
#define x1 dlp
#define y1 kdkdf
// ROAD to...                                                                                                                                                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
#define int long long
int n, k;
int x1[N], y1[N], x2[N], y2[N];

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

ll solve (ll j) {
	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 - (x1[i] - 1) % j) % j, x2[i] - x1[i] + 1);
			ll b = x2[i] % j;
			ll c = min ((j - (y1[i] - 1) % j) % j, y2[i] - y1[i] + 1);
			ll d = y2[i] % j;
			
			if (x1[i] + a > x2[i])
				b = 0;
			if (y1[i] + c > y2[i])
				d = 0;	
						
			bool e = calc (x1[i], y1[i], j);
			sm1[e] += a * c, sm2[e] += a * c;
			
			e = calc (x1[i], y1[i] + c, j);
			ll t = (y2[i] - y1[i] - 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 (x1[i], y2[i], j);
			sm1[e] += a * d, sm2[e] += a * d;
						
			ll xx1 = x1[i] + a;
			if (xx1 > x2[i])
				continue;
			
			e = calc (x2[i], y1[i], j);
			sm1[e] += b * c, sm2[e] += b * c;
			
			e = calc (x2[i], y1[i] + 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 (x1[i], y2[i], j);
			sm1[e] += b * d, sm2[e] += b * d;			
			
			ll xx2 = x2[i] - b;
			if (xx1 > xx2)
				continue;
			
			e = calc (xx1, y1[i], 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 = y1[i] + c;
			if (yy1 > y2[i])
				continue;
			
			e = calc (xx1, y2[i], 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 = y2[i] - d;
			if (yy1 > yy2)
				continue;
									
			e = calc (xx1, yy1, j);
			t = (yy2 - yy1 + 1) / j;
			ll t1 = (xx2 - xx1 + 1) / j;
			r = (((t + 1) / 2) * ((t1 + 1) / 2) + (t / 2) * (t1 / 2)) * j * j;
			sm1[e] += r, sm2[e] += r;
			r = ((t / 2) * ((t1 + 1) / 2) + ((t + 1) / 2) * (t1 / 2)) * j * j;
			sm1[!e] += r, sm2[!e] += r;
		}

	return min(sm2[0] - sm2[1], sm1[1] - sm1[0]);
}

 main () {               
    cin >> n >> k;
    For (i, 1, k) {
    	cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
    }

    ll ans = n * (ll)n;
    For (i, 1, n - 1) {
    	if (n % i == 0)
    		ans = min(ans, solve (i));
    }

    cout << ans;
    
    return Accepted;
}

// Coded By OB

Compilation message

chessboard.cpp:144:8: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  main () {               
        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 528 KB Output is correct
7 Correct 2 ms 528 KB Output is correct
8 Correct 2 ms 528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 3988 KB Output is correct
2 Correct 27 ms 3988 KB Output is correct
3 Correct 67 ms 4600 KB Output is correct
4 Correct 65 ms 5616 KB Output is correct
5 Correct 91 ms 7248 KB Output is correct
6 Correct 58 ms 7448 KB Output is correct
7 Correct 14 ms 7448 KB Output is correct
8 Correct 59 ms 8432 KB Output is correct
9 Correct 143 ms 12260 KB Output is correct
10 Correct 82 ms 12260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12260 KB Output is correct
2 Correct 2 ms 12260 KB Output is correct
3 Correct 2 ms 12260 KB Output is correct
4 Correct 4 ms 12260 KB Output is correct
5 Correct 2 ms 12260 KB Output is correct
6 Correct 3 ms 12260 KB Output is correct
7 Correct 3 ms 12260 KB Output is correct
8 Correct 3 ms 12260 KB Output is correct
9 Correct 3 ms 12260 KB Output is correct
10 Correct 2 ms 12260 KB Output is correct
11 Correct 3 ms 12260 KB Output is correct
12 Correct 2 ms 12260 KB Output is correct
13 Correct 3 ms 12260 KB Output is correct
14 Correct 3 ms 12260 KB Output is correct
15 Correct 3 ms 12260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12260 KB Output is correct
2 Correct 2 ms 12260 KB Output is correct
3 Correct 2 ms 12260 KB Output is correct
4 Correct 4 ms 12260 KB Output is correct
5 Correct 2 ms 12260 KB Output is correct
6 Correct 3 ms 12260 KB Output is correct
7 Correct 3 ms 12260 KB Output is correct
8 Correct 3 ms 12260 KB Output is correct
9 Correct 3 ms 12260 KB Output is correct
10 Correct 2 ms 12260 KB Output is correct
11 Correct 3 ms 12260 KB Output is correct
12 Correct 2 ms 12260 KB Output is correct
13 Correct 3 ms 12260 KB Output is correct
14 Correct 3 ms 12260 KB Output is correct
15 Correct 3 ms 12260 KB Output is correct
16 Correct 41 ms 12260 KB Output is correct
17 Correct 103 ms 15180 KB Output is correct
18 Correct 147 ms 17264 KB Output is correct
19 Correct 410 ms 18528 KB Output is correct
20 Correct 424 ms 20212 KB Output is correct
21 Correct 101 ms 21016 KB Output is correct
22 Correct 4 ms 21016 KB Output is correct
23 Correct 85 ms 21016 KB Output is correct
24 Correct 135 ms 23444 KB Output is correct
25 Correct 19 ms 23444 KB Output is correct
26 Correct 90 ms 23652 KB Output is correct
27 Correct 120 ms 24952 KB Output is correct
28 Correct 145 ms 27396 KB Output is correct
29 Correct 43 ms 27396 KB Output is correct
30 Correct 6 ms 27396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 3988 KB Output is correct
2 Correct 27 ms 3988 KB Output is correct
3 Correct 67 ms 4600 KB Output is correct
4 Correct 65 ms 5616 KB Output is correct
5 Correct 91 ms 7248 KB Output is correct
6 Correct 58 ms 7448 KB Output is correct
7 Correct 14 ms 7448 KB Output is correct
8 Correct 59 ms 8432 KB Output is correct
9 Correct 143 ms 12260 KB Output is correct
10 Correct 82 ms 12260 KB Output is correct
11 Correct 3 ms 12260 KB Output is correct
12 Correct 2 ms 12260 KB Output is correct
13 Correct 2 ms 12260 KB Output is correct
14 Correct 4 ms 12260 KB Output is correct
15 Correct 2 ms 12260 KB Output is correct
16 Correct 3 ms 12260 KB Output is correct
17 Correct 3 ms 12260 KB Output is correct
18 Correct 3 ms 12260 KB Output is correct
19 Correct 3 ms 12260 KB Output is correct
20 Correct 2 ms 12260 KB Output is correct
21 Correct 3 ms 12260 KB Output is correct
22 Correct 2 ms 12260 KB Output is correct
23 Correct 3 ms 12260 KB Output is correct
24 Correct 3 ms 12260 KB Output is correct
25 Correct 3 ms 12260 KB Output is correct
26 Correct 41 ms 12260 KB Output is correct
27 Correct 103 ms 15180 KB Output is correct
28 Correct 147 ms 17264 KB Output is correct
29 Correct 410 ms 18528 KB Output is correct
30 Correct 424 ms 20212 KB Output is correct
31 Correct 101 ms 21016 KB Output is correct
32 Correct 4 ms 21016 KB Output is correct
33 Correct 85 ms 21016 KB Output is correct
34 Correct 135 ms 23444 KB Output is correct
35 Correct 19 ms 23444 KB Output is correct
36 Correct 90 ms 23652 KB Output is correct
37 Correct 120 ms 24952 KB Output is correct
38 Correct 145 ms 27396 KB Output is correct
39 Correct 43 ms 27396 KB Output is correct
40 Correct 6 ms 27396 KB Output is correct
41 Correct 355 ms 29576 KB Output is correct
42 Correct 181 ms 32212 KB Output is correct
43 Correct 228 ms 33732 KB Output is correct
44 Correct 177 ms 36208 KB Output is correct
45 Correct 156 ms 37396 KB Output is correct
46 Correct 376 ms 37396 KB Output is correct
47 Correct 138 ms 37396 KB Output is correct
48 Correct 197 ms 37396 KB Output is correct
49 Correct 157 ms 37396 KB Output is correct
50 Correct 1463 ms 37396 KB Output is correct
51 Correct 1542 ms 37396 KB Output is correct
52 Correct 1404 ms 37396 KB Output is correct
53 Correct 1499 ms 37396 KB Output is correct
54 Correct 1397 ms 37396 KB Output is correct
55 Correct 1612 ms 37500 KB Output is correct
56 Correct 1372 ms 37500 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 508 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 528 KB Output is correct
7 Correct 2 ms 528 KB Output is correct
8 Correct 2 ms 528 KB Output is correct
9 Correct 103 ms 3988 KB Output is correct
10 Correct 27 ms 3988 KB Output is correct
11 Correct 67 ms 4600 KB Output is correct
12 Correct 65 ms 5616 KB Output is correct
13 Correct 91 ms 7248 KB Output is correct
14 Correct 58 ms 7448 KB Output is correct
15 Correct 14 ms 7448 KB Output is correct
16 Correct 59 ms 8432 KB Output is correct
17 Correct 143 ms 12260 KB Output is correct
18 Correct 82 ms 12260 KB Output is correct
19 Correct 3 ms 12260 KB Output is correct
20 Correct 2 ms 12260 KB Output is correct
21 Correct 2 ms 12260 KB Output is correct
22 Correct 4 ms 12260 KB Output is correct
23 Correct 2 ms 12260 KB Output is correct
24 Correct 3 ms 12260 KB Output is correct
25 Correct 3 ms 12260 KB Output is correct
26 Correct 3 ms 12260 KB Output is correct
27 Correct 3 ms 12260 KB Output is correct
28 Correct 2 ms 12260 KB Output is correct
29 Correct 3 ms 12260 KB Output is correct
30 Correct 2 ms 12260 KB Output is correct
31 Correct 3 ms 12260 KB Output is correct
32 Correct 3 ms 12260 KB Output is correct
33 Correct 3 ms 12260 KB Output is correct
34 Correct 41 ms 12260 KB Output is correct
35 Correct 103 ms 15180 KB Output is correct
36 Correct 147 ms 17264 KB Output is correct
37 Correct 410 ms 18528 KB Output is correct
38 Correct 424 ms 20212 KB Output is correct
39 Correct 101 ms 21016 KB Output is correct
40 Correct 4 ms 21016 KB Output is correct
41 Correct 85 ms 21016 KB Output is correct
42 Correct 135 ms 23444 KB Output is correct
43 Correct 19 ms 23444 KB Output is correct
44 Correct 90 ms 23652 KB Output is correct
45 Correct 120 ms 24952 KB Output is correct
46 Correct 145 ms 27396 KB Output is correct
47 Correct 43 ms 27396 KB Output is correct
48 Correct 6 ms 27396 KB Output is correct
49 Correct 355 ms 29576 KB Output is correct
50 Correct 181 ms 32212 KB Output is correct
51 Correct 228 ms 33732 KB Output is correct
52 Correct 177 ms 36208 KB Output is correct
53 Correct 156 ms 37396 KB Output is correct
54 Correct 376 ms 37396 KB Output is correct
55 Correct 138 ms 37396 KB Output is correct
56 Correct 197 ms 37396 KB Output is correct
57 Correct 157 ms 37396 KB Output is correct
58 Correct 1463 ms 37396 KB Output is correct
59 Correct 1542 ms 37396 KB Output is correct
60 Correct 1404 ms 37396 KB Output is correct
61 Correct 1499 ms 37396 KB Output is correct
62 Correct 1397 ms 37396 KB Output is correct
63 Correct 1612 ms 37500 KB Output is correct
64 Correct 1372 ms 37500 KB Output is correct
65 Correct 2 ms 37500 KB Output is correct
66 Correct 2 ms 37500 KB Output is correct
67 Incorrect 1572 ms 39544 KB Output isn't correct
68 Halted 0 ms 0 KB -