Submission #40363

# Submission time Handle Problem Language Result Execution time Memory
40363 2018-01-31T12:03:33 Z model_code Chessboard (IZhO18_chessboard) C++11
100 / 100
1200 ms 2292 KB
//Solution by Tima
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <bitset>
#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
#define y1 sda
using namespace std;    
const int N = int(3e5), mod = int(1e9)  + 7; 

int n, k, x1[N], y1[N], x2[N], y2[N];
ll ans;
int pos;

inline ll gety(ll y,ll len){
	if(y <= 0) return 0;
	ll res = (y / len) / 2 * len;
	if((y / len) & 1) res += y % len + 1;
	return res;
}

inline ll getx(ll x,ll len){
	if(x <= 0) return 0;
	ll res = (x / len) / 2 * len;
	if((x / len) & 1) res += x % len + 1;
	return res;
}

void solve(int len){
	ll odd = 0, even = 0;
	for(int i = 1,xx,yy; i <= k; i++){
		ll o1 = gety(y2[i], len) - gety(y1[i] - 1, len);
		ll e1 = (y2[i] - y1[i] + 1) - o1;
		ll o2 = getx(x2[i], len) -  getx(x1[i] - 1, len); 
		ll e2 = (x2[i] - x1[i] + 1) - o2;
		xx = x1[i] / len;
		yy = y1[i] / len;
		if(xx & 1) swap(o1,e1);
		if(yy & 1) swap(o2,e2);
		ll od = 0, ev = 0;
		if((xx + yy) & 1){
			od = e1 * e2 + o1 * o2;
		}
		else{
		    od = o1 * e2 + e1 * o2;
		}
		ev = 1ll * (x2[i] - x1[i] + 1) * (y2[i] - y1[i] + 1) - od;
		
		odd += od;
		even += ev;
	}
	ll cnt = 1ll * (n / len) * (n / len);
	ll res = min(cnt / 2 * len * len + even - odd, (cnt + 1) / 2 * len * len + odd - even);
	if(res < ans){
	    pos = len;
		ans = res;
	}
}

int main () {
	ans = (ll)(1e18);
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= k; i++){
		scanf("%d%d%d%d", &x1[i], &y1[i], &x2[i], &y2[i]);
		x1[i]--,y1[i]--,x2[i]--,y2[i]--;
	}
	for(int i = 1; i * i <= n; i++){
		if(n % i == 0){
			solve(i);
			if(i > 1) solve(n / i);
		}
	}
	printf("%lld", ans);


return 0;
}

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:81:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &k);
                       ^
chessboard.cpp:83:52: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d%d", &x1[i], &y1[i], &x2[i], &y2[i]);
                                                    ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 1 ms 376 KB Output is correct
3 Correct 1 ms 432 KB Output is correct
4 Correct 1 ms 448 KB Output is correct
5 Correct 2 ms 496 KB Output is correct
6 Correct 1 ms 548 KB Output is correct
7 Correct 1 ms 548 KB Output is correct
8 Correct 1 ms 548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 1464 KB Output is correct
2 Correct 12 ms 1464 KB Output is correct
3 Correct 24 ms 1464 KB Output is correct
4 Correct 24 ms 1464 KB Output is correct
5 Correct 31 ms 1464 KB Output is correct
6 Correct 20 ms 1464 KB Output is correct
7 Correct 5 ms 1464 KB Output is correct
8 Correct 20 ms 1464 KB Output is correct
9 Correct 50 ms 1992 KB Output is correct
10 Correct 47 ms 1992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1992 KB Output is correct
2 Correct 1 ms 1992 KB Output is correct
3 Correct 2 ms 1992 KB Output is correct
4 Correct 3 ms 1992 KB Output is correct
5 Correct 2 ms 1992 KB Output is correct
6 Correct 2 ms 1992 KB Output is correct
7 Correct 3 ms 1992 KB Output is correct
8 Correct 2 ms 1992 KB Output is correct
9 Correct 2 ms 1992 KB Output is correct
10 Correct 1 ms 1992 KB Output is correct
11 Correct 2 ms 1992 KB Output is correct
12 Correct 2 ms 1992 KB Output is correct
13 Correct 2 ms 1992 KB Output is correct
14 Correct 2 ms 1992 KB Output is correct
15 Correct 2 ms 1992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1992 KB Output is correct
2 Correct 1 ms 1992 KB Output is correct
3 Correct 2 ms 1992 KB Output is correct
4 Correct 3 ms 1992 KB Output is correct
5 Correct 2 ms 1992 KB Output is correct
6 Correct 2 ms 1992 KB Output is correct
7 Correct 3 ms 1992 KB Output is correct
8 Correct 2 ms 1992 KB Output is correct
9 Correct 2 ms 1992 KB Output is correct
10 Correct 1 ms 1992 KB Output is correct
11 Correct 2 ms 1992 KB Output is correct
12 Correct 2 ms 1992 KB Output is correct
13 Correct 2 ms 1992 KB Output is correct
14 Correct 2 ms 1992 KB Output is correct
15 Correct 2 ms 1992 KB Output is correct
16 Correct 20 ms 1992 KB Output is correct
17 Correct 46 ms 1992 KB Output is correct
18 Correct 64 ms 2160 KB Output is correct
19 Correct 264 ms 2160 KB Output is correct
20 Correct 267 ms 2160 KB Output is correct
21 Correct 46 ms 2160 KB Output is correct
22 Correct 3 ms 2160 KB Output is correct
23 Correct 47 ms 2160 KB Output is correct
24 Correct 61 ms 2160 KB Output is correct
25 Correct 10 ms 2160 KB Output is correct
26 Correct 59 ms 2160 KB Output is correct
27 Correct 61 ms 2160 KB Output is correct
28 Correct 63 ms 2160 KB Output is correct
29 Correct 29 ms 2160 KB Output is correct
30 Correct 5 ms 2160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 1464 KB Output is correct
2 Correct 12 ms 1464 KB Output is correct
3 Correct 24 ms 1464 KB Output is correct
4 Correct 24 ms 1464 KB Output is correct
5 Correct 31 ms 1464 KB Output is correct
6 Correct 20 ms 1464 KB Output is correct
7 Correct 5 ms 1464 KB Output is correct
8 Correct 20 ms 1464 KB Output is correct
9 Correct 50 ms 1992 KB Output is correct
10 Correct 47 ms 1992 KB Output is correct
11 Correct 2 ms 1992 KB Output is correct
12 Correct 1 ms 1992 KB Output is correct
13 Correct 2 ms 1992 KB Output is correct
14 Correct 3 ms 1992 KB Output is correct
15 Correct 2 ms 1992 KB Output is correct
16 Correct 2 ms 1992 KB Output is correct
17 Correct 3 ms 1992 KB Output is correct
18 Correct 2 ms 1992 KB Output is correct
19 Correct 2 ms 1992 KB Output is correct
20 Correct 1 ms 1992 KB Output is correct
21 Correct 2 ms 1992 KB Output is correct
22 Correct 2 ms 1992 KB Output is correct
23 Correct 2 ms 1992 KB Output is correct
24 Correct 2 ms 1992 KB Output is correct
25 Correct 2 ms 1992 KB Output is correct
26 Correct 20 ms 1992 KB Output is correct
27 Correct 46 ms 1992 KB Output is correct
28 Correct 64 ms 2160 KB Output is correct
29 Correct 264 ms 2160 KB Output is correct
30 Correct 267 ms 2160 KB Output is correct
31 Correct 46 ms 2160 KB Output is correct
32 Correct 3 ms 2160 KB Output is correct
33 Correct 47 ms 2160 KB Output is correct
34 Correct 61 ms 2160 KB Output is correct
35 Correct 10 ms 2160 KB Output is correct
36 Correct 59 ms 2160 KB Output is correct
37 Correct 61 ms 2160 KB Output is correct
38 Correct 63 ms 2160 KB Output is correct
39 Correct 29 ms 2160 KB Output is correct
40 Correct 5 ms 2160 KB Output is correct
41 Correct 220 ms 2160 KB Output is correct
42 Correct 72 ms 2160 KB Output is correct
43 Correct 135 ms 2160 KB Output is correct
44 Correct 70 ms 2160 KB Output is correct
45 Correct 59 ms 2160 KB Output is correct
46 Correct 227 ms 2160 KB Output is correct
47 Correct 67 ms 2160 KB Output is correct
48 Correct 97 ms 2160 KB Output is correct
49 Correct 61 ms 2160 KB Output is correct
50 Correct 1020 ms 2160 KB Output is correct
51 Correct 1124 ms 2160 KB Output is correct
52 Correct 1027 ms 2160 KB Output is correct
53 Correct 1114 ms 2288 KB Output is correct
54 Correct 1038 ms 2288 KB Output is correct
55 Correct 1115 ms 2292 KB Output is correct
56 Correct 986 ms 2292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 1 ms 376 KB Output is correct
3 Correct 1 ms 432 KB Output is correct
4 Correct 1 ms 448 KB Output is correct
5 Correct 2 ms 496 KB Output is correct
6 Correct 1 ms 548 KB Output is correct
7 Correct 1 ms 548 KB Output is correct
8 Correct 1 ms 548 KB Output is correct
9 Correct 37 ms 1464 KB Output is correct
10 Correct 12 ms 1464 KB Output is correct
11 Correct 24 ms 1464 KB Output is correct
12 Correct 24 ms 1464 KB Output is correct
13 Correct 31 ms 1464 KB Output is correct
14 Correct 20 ms 1464 KB Output is correct
15 Correct 5 ms 1464 KB Output is correct
16 Correct 20 ms 1464 KB Output is correct
17 Correct 50 ms 1992 KB Output is correct
18 Correct 47 ms 1992 KB Output is correct
19 Correct 2 ms 1992 KB Output is correct
20 Correct 1 ms 1992 KB Output is correct
21 Correct 2 ms 1992 KB Output is correct
22 Correct 3 ms 1992 KB Output is correct
23 Correct 2 ms 1992 KB Output is correct
24 Correct 2 ms 1992 KB Output is correct
25 Correct 3 ms 1992 KB Output is correct
26 Correct 2 ms 1992 KB Output is correct
27 Correct 2 ms 1992 KB Output is correct
28 Correct 1 ms 1992 KB Output is correct
29 Correct 2 ms 1992 KB Output is correct
30 Correct 2 ms 1992 KB Output is correct
31 Correct 2 ms 1992 KB Output is correct
32 Correct 2 ms 1992 KB Output is correct
33 Correct 2 ms 1992 KB Output is correct
34 Correct 20 ms 1992 KB Output is correct
35 Correct 46 ms 1992 KB Output is correct
36 Correct 64 ms 2160 KB Output is correct
37 Correct 264 ms 2160 KB Output is correct
38 Correct 267 ms 2160 KB Output is correct
39 Correct 46 ms 2160 KB Output is correct
40 Correct 3 ms 2160 KB Output is correct
41 Correct 47 ms 2160 KB Output is correct
42 Correct 61 ms 2160 KB Output is correct
43 Correct 10 ms 2160 KB Output is correct
44 Correct 59 ms 2160 KB Output is correct
45 Correct 61 ms 2160 KB Output is correct
46 Correct 63 ms 2160 KB Output is correct
47 Correct 29 ms 2160 KB Output is correct
48 Correct 5 ms 2160 KB Output is correct
49 Correct 220 ms 2160 KB Output is correct
50 Correct 72 ms 2160 KB Output is correct
51 Correct 135 ms 2160 KB Output is correct
52 Correct 70 ms 2160 KB Output is correct
53 Correct 59 ms 2160 KB Output is correct
54 Correct 227 ms 2160 KB Output is correct
55 Correct 67 ms 2160 KB Output is correct
56 Correct 97 ms 2160 KB Output is correct
57 Correct 61 ms 2160 KB Output is correct
58 Correct 1020 ms 2160 KB Output is correct
59 Correct 1124 ms 2160 KB Output is correct
60 Correct 1027 ms 2160 KB Output is correct
61 Correct 1114 ms 2288 KB Output is correct
62 Correct 1038 ms 2288 KB Output is correct
63 Correct 1115 ms 2292 KB Output is correct
64 Correct 986 ms 2292 KB Output is correct
65 Correct 1 ms 2292 KB Output is correct
66 Correct 2 ms 2292 KB Output is correct
67 Correct 1130 ms 2292 KB Output is correct
68 Correct 1104 ms 2292 KB Output is correct
69 Correct 938 ms 2292 KB Output is correct
70 Correct 1037 ms 2292 KB Output is correct
71 Correct 1042 ms 2292 KB Output is correct
72 Correct 979 ms 2292 KB Output is correct
73 Correct 1045 ms 2292 KB Output is correct
74 Correct 1115 ms 2292 KB Output is correct
75 Correct 1012 ms 2292 KB Output is correct
76 Correct 1121 ms 2292 KB Output is correct
77 Correct 179 ms 2292 KB Output is correct
78 Correct 77 ms 2292 KB Output is correct
79 Correct 128 ms 2292 KB Output is correct
80 Correct 142 ms 2292 KB Output is correct
81 Correct 124 ms 2292 KB Output is correct
82 Correct 112 ms 2292 KB Output is correct
83 Correct 86 ms 2292 KB Output is correct
84 Correct 659 ms 2292 KB Output is correct
85 Correct 1200 ms 2292 KB Output is correct
86 Correct 2 ms 2292 KB Output is correct
87 Correct 1 ms 2292 KB Output is correct
88 Correct 1163 ms 2292 KB Output is correct
89 Correct 231 ms 2292 KB Output is correct
90 Correct 1 ms 2292 KB Output is correct