답안 #50840

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
50840 2018-06-13T16:27:42 Z Nicksechko Chessboard (IZhO18_chessboard) C++14
100 / 100
1370 ms 103576 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:7: 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:8: 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]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 524 KB Output is correct
4 Correct 2 ms 524 KB Output is correct
5 Correct 3 ms 524 KB Output is correct
6 Correct 2 ms 524 KB Output is correct
7 Correct 2 ms 524 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 1676 KB Output is correct
2 Correct 14 ms 1676 KB Output is correct
3 Correct 42 ms 2560 KB Output is correct
4 Correct 42 ms 3652 KB Output is correct
5 Correct 36 ms 4976 KB Output is correct
6 Correct 23 ms 5504 KB Output is correct
7 Correct 7 ms 5504 KB Output is correct
8 Correct 29 ms 6592 KB Output is correct
9 Correct 55 ms 9720 KB Output is correct
10 Correct 30 ms 10044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10044 KB Output is correct
2 Correct 3 ms 10044 KB Output is correct
3 Correct 3 ms 10044 KB Output is correct
4 Correct 1 ms 10044 KB Output is correct
5 Correct 2 ms 10044 KB Output is correct
6 Correct 6 ms 10044 KB Output is correct
7 Correct 2 ms 10044 KB Output is correct
8 Correct 4 ms 10044 KB Output is correct
9 Correct 3 ms 10044 KB Output is correct
10 Correct 2 ms 10044 KB Output is correct
11 Correct 3 ms 10044 KB Output is correct
12 Correct 2 ms 10044 KB Output is correct
13 Correct 3 ms 10044 KB Output is correct
14 Correct 3 ms 10044 KB Output is correct
15 Correct 2 ms 10044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10044 KB Output is correct
2 Correct 3 ms 10044 KB Output is correct
3 Correct 3 ms 10044 KB Output is correct
4 Correct 1 ms 10044 KB Output is correct
5 Correct 2 ms 10044 KB Output is correct
6 Correct 6 ms 10044 KB Output is correct
7 Correct 2 ms 10044 KB Output is correct
8 Correct 4 ms 10044 KB Output is correct
9 Correct 3 ms 10044 KB Output is correct
10 Correct 2 ms 10044 KB Output is correct
11 Correct 3 ms 10044 KB Output is correct
12 Correct 2 ms 10044 KB Output is correct
13 Correct 3 ms 10044 KB Output is correct
14 Correct 3 ms 10044 KB Output is correct
15 Correct 2 ms 10044 KB Output is correct
16 Correct 20 ms 10196 KB Output is correct
17 Correct 45 ms 12572 KB Output is correct
18 Correct 97 ms 14496 KB Output is correct
19 Correct 264 ms 15676 KB Output is correct
20 Correct 335 ms 17496 KB Output is correct
21 Correct 43 ms 18620 KB Output is correct
22 Correct 3 ms 18620 KB Output is correct
23 Correct 46 ms 18620 KB Output is correct
24 Correct 64 ms 20848 KB Output is correct
25 Correct 12 ms 20848 KB Output is correct
26 Correct 45 ms 21248 KB Output is correct
27 Correct 60 ms 22592 KB Output is correct
28 Correct 70 ms 24748 KB Output is correct
29 Correct 18 ms 24748 KB Output is correct
30 Correct 5 ms 24748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 1676 KB Output is correct
2 Correct 14 ms 1676 KB Output is correct
3 Correct 42 ms 2560 KB Output is correct
4 Correct 42 ms 3652 KB Output is correct
5 Correct 36 ms 4976 KB Output is correct
6 Correct 23 ms 5504 KB Output is correct
7 Correct 7 ms 5504 KB Output is correct
8 Correct 29 ms 6592 KB Output is correct
9 Correct 55 ms 9720 KB Output is correct
10 Correct 30 ms 10044 KB Output is correct
11 Correct 3 ms 10044 KB Output is correct
12 Correct 3 ms 10044 KB Output is correct
13 Correct 3 ms 10044 KB Output is correct
14 Correct 1 ms 10044 KB Output is correct
15 Correct 2 ms 10044 KB Output is correct
16 Correct 6 ms 10044 KB Output is correct
17 Correct 2 ms 10044 KB Output is correct
18 Correct 4 ms 10044 KB Output is correct
19 Correct 3 ms 10044 KB Output is correct
20 Correct 2 ms 10044 KB Output is correct
21 Correct 3 ms 10044 KB Output is correct
22 Correct 2 ms 10044 KB Output is correct
23 Correct 3 ms 10044 KB Output is correct
24 Correct 3 ms 10044 KB Output is correct
25 Correct 2 ms 10044 KB Output is correct
26 Correct 20 ms 10196 KB Output is correct
27 Correct 45 ms 12572 KB Output is correct
28 Correct 97 ms 14496 KB Output is correct
29 Correct 264 ms 15676 KB Output is correct
30 Correct 335 ms 17496 KB Output is correct
31 Correct 43 ms 18620 KB Output is correct
32 Correct 3 ms 18620 KB Output is correct
33 Correct 46 ms 18620 KB Output is correct
34 Correct 64 ms 20848 KB Output is correct
35 Correct 12 ms 20848 KB Output is correct
36 Correct 45 ms 21248 KB Output is correct
37 Correct 60 ms 22592 KB Output is correct
38 Correct 70 ms 24748 KB Output is correct
39 Correct 18 ms 24748 KB Output is correct
40 Correct 5 ms 24748 KB Output is correct
41 Correct 211 ms 26992 KB Output is correct
42 Correct 80 ms 29428 KB Output is correct
43 Correct 141 ms 31148 KB Output is correct
44 Correct 79 ms 33664 KB Output is correct
45 Correct 58 ms 36072 KB Output is correct
46 Correct 238 ms 38420 KB Output is correct
47 Correct 52 ms 40060 KB Output is correct
48 Correct 100 ms 42240 KB Output is correct
49 Correct 70 ms 44124 KB Output is correct
50 Correct 1118 ms 46500 KB Output is correct
51 Correct 1140 ms 48912 KB Output is correct
52 Correct 1093 ms 51084 KB Output is correct
53 Correct 1197 ms 53352 KB Output is correct
54 Correct 1222 ms 55368 KB Output is correct
55 Correct 1370 ms 57936 KB Output is correct
56 Correct 1066 ms 59784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 524 KB Output is correct
4 Correct 2 ms 524 KB Output is correct
5 Correct 3 ms 524 KB Output is correct
6 Correct 2 ms 524 KB Output is correct
7 Correct 2 ms 524 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 37 ms 1676 KB Output is correct
10 Correct 14 ms 1676 KB Output is correct
11 Correct 42 ms 2560 KB Output is correct
12 Correct 42 ms 3652 KB Output is correct
13 Correct 36 ms 4976 KB Output is correct
14 Correct 23 ms 5504 KB Output is correct
15 Correct 7 ms 5504 KB Output is correct
16 Correct 29 ms 6592 KB Output is correct
17 Correct 55 ms 9720 KB Output is correct
18 Correct 30 ms 10044 KB Output is correct
19 Correct 3 ms 10044 KB Output is correct
20 Correct 3 ms 10044 KB Output is correct
21 Correct 3 ms 10044 KB Output is correct
22 Correct 1 ms 10044 KB Output is correct
23 Correct 2 ms 10044 KB Output is correct
24 Correct 6 ms 10044 KB Output is correct
25 Correct 2 ms 10044 KB Output is correct
26 Correct 4 ms 10044 KB Output is correct
27 Correct 3 ms 10044 KB Output is correct
28 Correct 2 ms 10044 KB Output is correct
29 Correct 3 ms 10044 KB Output is correct
30 Correct 2 ms 10044 KB Output is correct
31 Correct 3 ms 10044 KB Output is correct
32 Correct 3 ms 10044 KB Output is correct
33 Correct 2 ms 10044 KB Output is correct
34 Correct 20 ms 10196 KB Output is correct
35 Correct 45 ms 12572 KB Output is correct
36 Correct 97 ms 14496 KB Output is correct
37 Correct 264 ms 15676 KB Output is correct
38 Correct 335 ms 17496 KB Output is correct
39 Correct 43 ms 18620 KB Output is correct
40 Correct 3 ms 18620 KB Output is correct
41 Correct 46 ms 18620 KB Output is correct
42 Correct 64 ms 20848 KB Output is correct
43 Correct 12 ms 20848 KB Output is correct
44 Correct 45 ms 21248 KB Output is correct
45 Correct 60 ms 22592 KB Output is correct
46 Correct 70 ms 24748 KB Output is correct
47 Correct 18 ms 24748 KB Output is correct
48 Correct 5 ms 24748 KB Output is correct
49 Correct 211 ms 26992 KB Output is correct
50 Correct 80 ms 29428 KB Output is correct
51 Correct 141 ms 31148 KB Output is correct
52 Correct 79 ms 33664 KB Output is correct
53 Correct 58 ms 36072 KB Output is correct
54 Correct 238 ms 38420 KB Output is correct
55 Correct 52 ms 40060 KB Output is correct
56 Correct 100 ms 42240 KB Output is correct
57 Correct 70 ms 44124 KB Output is correct
58 Correct 1118 ms 46500 KB Output is correct
59 Correct 1140 ms 48912 KB Output is correct
60 Correct 1093 ms 51084 KB Output is correct
61 Correct 1197 ms 53352 KB Output is correct
62 Correct 1222 ms 55368 KB Output is correct
63 Correct 1370 ms 57936 KB Output is correct
64 Correct 1066 ms 59784 KB Output is correct
65 Correct 3 ms 59784 KB Output is correct
66 Correct 2 ms 59784 KB Output is correct
67 Correct 1229 ms 62280 KB Output is correct
68 Correct 1089 ms 64524 KB Output is correct
69 Correct 993 ms 66232 KB Output is correct
70 Correct 1091 ms 68580 KB Output is correct
71 Correct 1090 ms 70744 KB Output is correct
72 Correct 995 ms 72796 KB Output is correct
73 Correct 993 ms 74844 KB Output is correct
74 Correct 1229 ms 77232 KB Output is correct
75 Correct 1085 ms 79220 KB Output is correct
76 Correct 1101 ms 81656 KB Output is correct
77 Correct 182 ms 83916 KB Output is correct
78 Correct 93 ms 85948 KB Output is correct
79 Correct 137 ms 87844 KB Output is correct
80 Correct 148 ms 89988 KB Output is correct
81 Correct 184 ms 92032 KB Output is correct
82 Correct 120 ms 94516 KB Output is correct
83 Correct 94 ms 96472 KB Output is correct
84 Correct 684 ms 98832 KB Output is correct
85 Correct 1180 ms 101184 KB Output is correct
86 Correct 4 ms 101184 KB Output is correct
87 Correct 2 ms 101184 KB Output is correct
88 Correct 1177 ms 103576 KB Output is correct
89 Correct 236 ms 103576 KB Output is correct
90 Correct 3 ms 103576 KB Output is correct