답안 #89273

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
89273 2018-12-11T08:16:44 Z dimash241 Chessboard (IZhO18_chessboard) C++17
70 / 100
1597 ms 3836 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 = INF;
    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 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 2 ms 572 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 2508 KB Output is correct
2 Correct 24 ms 2508 KB Output is correct
3 Correct 63 ms 2508 KB Output is correct
4 Correct 65 ms 2508 KB Output is correct
5 Correct 87 ms 2508 KB Output is correct
6 Correct 58 ms 2508 KB Output is correct
7 Correct 14 ms 2508 KB Output is correct
8 Correct 57 ms 2508 KB Output is correct
9 Correct 141 ms 3388 KB Output is correct
10 Correct 79 ms 3388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3388 KB Output is correct
2 Correct 2 ms 3388 KB Output is correct
3 Correct 2 ms 3388 KB Output is correct
4 Correct 4 ms 3388 KB Output is correct
5 Correct 3 ms 3388 KB Output is correct
6 Correct 3 ms 3388 KB Output is correct
7 Correct 3 ms 3388 KB Output is correct
8 Correct 3 ms 3388 KB Output is correct
9 Correct 2 ms 3388 KB Output is correct
10 Correct 2 ms 3388 KB Output is correct
11 Correct 3 ms 3388 KB Output is correct
12 Correct 3 ms 3388 KB Output is correct
13 Correct 4 ms 3388 KB Output is correct
14 Correct 4 ms 3388 KB Output is correct
15 Correct 3 ms 3388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3388 KB Output is correct
2 Correct 2 ms 3388 KB Output is correct
3 Correct 2 ms 3388 KB Output is correct
4 Correct 4 ms 3388 KB Output is correct
5 Correct 3 ms 3388 KB Output is correct
6 Correct 3 ms 3388 KB Output is correct
7 Correct 3 ms 3388 KB Output is correct
8 Correct 3 ms 3388 KB Output is correct
9 Correct 2 ms 3388 KB Output is correct
10 Correct 2 ms 3388 KB Output is correct
11 Correct 3 ms 3388 KB Output is correct
12 Correct 3 ms 3388 KB Output is correct
13 Correct 4 ms 3388 KB Output is correct
14 Correct 4 ms 3388 KB Output is correct
15 Correct 3 ms 3388 KB Output is correct
16 Correct 43 ms 3388 KB Output is correct
17 Correct 105 ms 3388 KB Output is correct
18 Correct 148 ms 3836 KB Output is correct
19 Correct 396 ms 3836 KB Output is correct
20 Correct 439 ms 3836 KB Output is correct
21 Correct 102 ms 3836 KB Output is correct
22 Correct 3 ms 3836 KB Output is correct
23 Correct 83 ms 3836 KB Output is correct
24 Correct 132 ms 3836 KB Output is correct
25 Correct 18 ms 3836 KB Output is correct
26 Correct 86 ms 3836 KB Output is correct
27 Correct 120 ms 3836 KB Output is correct
28 Correct 142 ms 3836 KB Output is correct
29 Correct 42 ms 3836 KB Output is correct
30 Correct 7 ms 3836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 2508 KB Output is correct
2 Correct 24 ms 2508 KB Output is correct
3 Correct 63 ms 2508 KB Output is correct
4 Correct 65 ms 2508 KB Output is correct
5 Correct 87 ms 2508 KB Output is correct
6 Correct 58 ms 2508 KB Output is correct
7 Correct 14 ms 2508 KB Output is correct
8 Correct 57 ms 2508 KB Output is correct
9 Correct 141 ms 3388 KB Output is correct
10 Correct 79 ms 3388 KB Output is correct
11 Correct 3 ms 3388 KB Output is correct
12 Correct 2 ms 3388 KB Output is correct
13 Correct 2 ms 3388 KB Output is correct
14 Correct 4 ms 3388 KB Output is correct
15 Correct 3 ms 3388 KB Output is correct
16 Correct 3 ms 3388 KB Output is correct
17 Correct 3 ms 3388 KB Output is correct
18 Correct 3 ms 3388 KB Output is correct
19 Correct 2 ms 3388 KB Output is correct
20 Correct 2 ms 3388 KB Output is correct
21 Correct 3 ms 3388 KB Output is correct
22 Correct 3 ms 3388 KB Output is correct
23 Correct 4 ms 3388 KB Output is correct
24 Correct 4 ms 3388 KB Output is correct
25 Correct 3 ms 3388 KB Output is correct
26 Correct 43 ms 3388 KB Output is correct
27 Correct 105 ms 3388 KB Output is correct
28 Correct 148 ms 3836 KB Output is correct
29 Correct 396 ms 3836 KB Output is correct
30 Correct 439 ms 3836 KB Output is correct
31 Correct 102 ms 3836 KB Output is correct
32 Correct 3 ms 3836 KB Output is correct
33 Correct 83 ms 3836 KB Output is correct
34 Correct 132 ms 3836 KB Output is correct
35 Correct 18 ms 3836 KB Output is correct
36 Correct 86 ms 3836 KB Output is correct
37 Correct 120 ms 3836 KB Output is correct
38 Correct 142 ms 3836 KB Output is correct
39 Correct 42 ms 3836 KB Output is correct
40 Correct 7 ms 3836 KB Output is correct
41 Correct 347 ms 3836 KB Output is correct
42 Correct 175 ms 3836 KB Output is correct
43 Correct 233 ms 3836 KB Output is correct
44 Correct 170 ms 3836 KB Output is correct
45 Correct 158 ms 3836 KB Output is correct
46 Correct 379 ms 3836 KB Output is correct
47 Correct 139 ms 3836 KB Output is correct
48 Correct 205 ms 3836 KB Output is correct
49 Correct 170 ms 3836 KB Output is correct
50 Correct 1448 ms 3836 KB Output is correct
51 Correct 1514 ms 3836 KB Output is correct
52 Correct 1405 ms 3836 KB Output is correct
53 Correct 1495 ms 3836 KB Output is correct
54 Correct 1377 ms 3836 KB Output is correct
55 Correct 1573 ms 3836 KB Output is correct
56 Correct 1370 ms 3836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 2 ms 572 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 101 ms 2508 KB Output is correct
10 Correct 24 ms 2508 KB Output is correct
11 Correct 63 ms 2508 KB Output is correct
12 Correct 65 ms 2508 KB Output is correct
13 Correct 87 ms 2508 KB Output is correct
14 Correct 58 ms 2508 KB Output is correct
15 Correct 14 ms 2508 KB Output is correct
16 Correct 57 ms 2508 KB Output is correct
17 Correct 141 ms 3388 KB Output is correct
18 Correct 79 ms 3388 KB Output is correct
19 Correct 3 ms 3388 KB Output is correct
20 Correct 2 ms 3388 KB Output is correct
21 Correct 2 ms 3388 KB Output is correct
22 Correct 4 ms 3388 KB Output is correct
23 Correct 3 ms 3388 KB Output is correct
24 Correct 3 ms 3388 KB Output is correct
25 Correct 3 ms 3388 KB Output is correct
26 Correct 3 ms 3388 KB Output is correct
27 Correct 2 ms 3388 KB Output is correct
28 Correct 2 ms 3388 KB Output is correct
29 Correct 3 ms 3388 KB Output is correct
30 Correct 3 ms 3388 KB Output is correct
31 Correct 4 ms 3388 KB Output is correct
32 Correct 4 ms 3388 KB Output is correct
33 Correct 3 ms 3388 KB Output is correct
34 Correct 43 ms 3388 KB Output is correct
35 Correct 105 ms 3388 KB Output is correct
36 Correct 148 ms 3836 KB Output is correct
37 Correct 396 ms 3836 KB Output is correct
38 Correct 439 ms 3836 KB Output is correct
39 Correct 102 ms 3836 KB Output is correct
40 Correct 3 ms 3836 KB Output is correct
41 Correct 83 ms 3836 KB Output is correct
42 Correct 132 ms 3836 KB Output is correct
43 Correct 18 ms 3836 KB Output is correct
44 Correct 86 ms 3836 KB Output is correct
45 Correct 120 ms 3836 KB Output is correct
46 Correct 142 ms 3836 KB Output is correct
47 Correct 42 ms 3836 KB Output is correct
48 Correct 7 ms 3836 KB Output is correct
49 Correct 347 ms 3836 KB Output is correct
50 Correct 175 ms 3836 KB Output is correct
51 Correct 233 ms 3836 KB Output is correct
52 Correct 170 ms 3836 KB Output is correct
53 Correct 158 ms 3836 KB Output is correct
54 Correct 379 ms 3836 KB Output is correct
55 Correct 139 ms 3836 KB Output is correct
56 Correct 205 ms 3836 KB Output is correct
57 Correct 170 ms 3836 KB Output is correct
58 Correct 1448 ms 3836 KB Output is correct
59 Correct 1514 ms 3836 KB Output is correct
60 Correct 1405 ms 3836 KB Output is correct
61 Correct 1495 ms 3836 KB Output is correct
62 Correct 1377 ms 3836 KB Output is correct
63 Correct 1573 ms 3836 KB Output is correct
64 Correct 1370 ms 3836 KB Output is correct
65 Correct 2 ms 3836 KB Output is correct
66 Correct 2 ms 3836 KB Output is correct
67 Incorrect 1597 ms 3836 KB Output isn't correct
68 Halted 0 ms 0 KB -