Submission #171663

# Submission time Handle Problem Language Result Execution time Memory
171663 2019-12-29T15:12:25 Z Lightning Chessboard (IZhO18_chessboard) C++14
70 / 100
476 ms 6008 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
#define y1 GG
#define int ll

const int N = 1e5 + 5;
const ll INF = 1e12 + 5;

//int sc[N][N];
int x1[N], x2[N], y1[N], y2[N];

void solve1(int n, int k) {
	for(int it = 1; it <= k; ++it) { 
		//int x1, y1, x2, y2;
		cin >> x1[it] >> y1[it] >> x2[it] >> y2[it];
		//cin >> x1 >> y1 >> x2 >> y2;
	}
	vector <int> d;
	d.pb(1);
	for(int i = 2; i * i <= n; ++i) {
		if(n % i == 0) {
			d.pb(i);
			if(i != n / i) d.pb(n / i);
		}
	}
	int ans = INF;
	for(int di : d) {
		/*int black = 0;
		for(int i = 1; i <= n; ++i) {
			bool vs = ((((i - 1) / di) & 1) ^ 1);
			for(int j = 1; j <= n; ++j) {
				if((((j - 1) / di) & 1) ^ vs) ++black;//cout << 1;
				//else cout << 2;	
			}
			//cout << '\n';
		}
		cout << '\n';
		if((row1 * cntrow1 + row2 * cntrow2) * di * di != black) {
			show(di);
			show(row1);
			show(cntrow1);
			show(row2);
			show(cntrow2);
			show(black);
		}*/
		int row1 = (n / di + 1) / 2, row2 = (n / di) / 2;
		int res1 = (row1 * row1 + row2 * row2) * di * di, res2 = n * n - res1;
		for(int it = 1; it <= k; ++it) {
			int i = x1[it], j = y1[it];
			bool vs = ((((i - 1) / di) & 1) ^ 1);
			if((((j - 1) / di) & 1) ^ vs) {++res2; --res1;}
			else {++res1; --res2;}
		}
		ans = min(ans, min(res1, res2));
	}
	cout << ans;
}

main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k;
	cin >> n >> k;
	//if(n <= 1000) {
		solve1(n, k);
	//} else {
	//	solve2(n, k);
	//}
	return 0;
}
/*
6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6

4 1
4 1 4 4

	If you only do what you can do, 
	You will never be more than you are now!	
*/

Compilation message

chessboard.cpp:83:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 1 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 2808 KB Output is correct
2 Correct 10 ms 1400 KB Output is correct
3 Correct 20 ms 2552 KB Output is correct
4 Correct 22 ms 2680 KB Output is correct
5 Correct 27 ms 3320 KB Output is correct
6 Correct 18 ms 2296 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
8 Correct 18 ms 2296 KB Output is correct
9 Correct 44 ms 5240 KB Output is correct
10 Correct 26 ms 3068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 15 ms 1656 KB Output is correct
17 Correct 35 ms 4396 KB Output is correct
18 Correct 47 ms 4972 KB Output is correct
19 Correct 113 ms 4636 KB Output is correct
20 Correct 129 ms 5112 KB Output is correct
21 Correct 35 ms 4216 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 57 ms 2296 KB Output is correct
24 Correct 43 ms 4572 KB Output is correct
25 Correct 7 ms 760 KB Output is correct
26 Correct 28 ms 3064 KB Output is correct
27 Correct 38 ms 3536 KB Output is correct
28 Correct 45 ms 4856 KB Output is correct
29 Correct 15 ms 1912 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 2808 KB Output is correct
2 Correct 10 ms 1400 KB Output is correct
3 Correct 20 ms 2552 KB Output is correct
4 Correct 22 ms 2680 KB Output is correct
5 Correct 27 ms 3320 KB Output is correct
6 Correct 18 ms 2296 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
8 Correct 18 ms 2296 KB Output is correct
9 Correct 44 ms 5240 KB Output is correct
10 Correct 26 ms 3068 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 15 ms 1656 KB Output is correct
27 Correct 35 ms 4396 KB Output is correct
28 Correct 47 ms 4972 KB Output is correct
29 Correct 113 ms 4636 KB Output is correct
30 Correct 129 ms 5112 KB Output is correct
31 Correct 35 ms 4216 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 57 ms 2296 KB Output is correct
34 Correct 43 ms 4572 KB Output is correct
35 Correct 7 ms 760 KB Output is correct
36 Correct 28 ms 3064 KB Output is correct
37 Correct 38 ms 3536 KB Output is correct
38 Correct 45 ms 4856 KB Output is correct
39 Correct 15 ms 1912 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
41 Correct 102 ms 4984 KB Output is correct
42 Correct 55 ms 5496 KB Output is correct
43 Correct 73 ms 5088 KB Output is correct
44 Correct 57 ms 5496 KB Output is correct
45 Correct 48 ms 5752 KB Output is correct
46 Correct 114 ms 5588 KB Output is correct
47 Correct 42 ms 5112 KB Output is correct
48 Correct 60 ms 5244 KB Output is correct
49 Correct 46 ms 4984 KB Output is correct
50 Correct 427 ms 5452 KB Output is correct
51 Correct 456 ms 5820 KB Output is correct
52 Correct 426 ms 5496 KB Output is correct
53 Correct 452 ms 5624 KB Output is correct
54 Correct 418 ms 5316 KB Output is correct
55 Correct 476 ms 6008 KB Output is correct
56 Correct 407 ms 5240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 1 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 31 ms 2808 KB Output is correct
10 Correct 10 ms 1400 KB Output is correct
11 Correct 20 ms 2552 KB Output is correct
12 Correct 22 ms 2680 KB Output is correct
13 Correct 27 ms 3320 KB Output is correct
14 Correct 18 ms 2296 KB Output is correct
15 Correct 6 ms 760 KB Output is correct
16 Correct 18 ms 2296 KB Output is correct
17 Correct 44 ms 5240 KB Output is correct
18 Correct 26 ms 3068 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 15 ms 1656 KB Output is correct
35 Correct 35 ms 4396 KB Output is correct
36 Correct 47 ms 4972 KB Output is correct
37 Correct 113 ms 4636 KB Output is correct
38 Correct 129 ms 5112 KB Output is correct
39 Correct 35 ms 4216 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 57 ms 2296 KB Output is correct
42 Correct 43 ms 4572 KB Output is correct
43 Correct 7 ms 760 KB Output is correct
44 Correct 28 ms 3064 KB Output is correct
45 Correct 38 ms 3536 KB Output is correct
46 Correct 45 ms 4856 KB Output is correct
47 Correct 15 ms 1912 KB Output is correct
48 Correct 3 ms 504 KB Output is correct
49 Correct 102 ms 4984 KB Output is correct
50 Correct 55 ms 5496 KB Output is correct
51 Correct 73 ms 5088 KB Output is correct
52 Correct 57 ms 5496 KB Output is correct
53 Correct 48 ms 5752 KB Output is correct
54 Correct 114 ms 5588 KB Output is correct
55 Correct 42 ms 5112 KB Output is correct
56 Correct 60 ms 5244 KB Output is correct
57 Correct 46 ms 4984 KB Output is correct
58 Correct 427 ms 5452 KB Output is correct
59 Correct 456 ms 5820 KB Output is correct
60 Correct 426 ms 5496 KB Output is correct
61 Correct 452 ms 5624 KB Output is correct
62 Correct 418 ms 5316 KB Output is correct
63 Correct 476 ms 6008 KB Output is correct
64 Correct 407 ms 5240 KB Output is correct
65 Correct 2 ms 504 KB Output is correct
66 Incorrect 2 ms 376 KB Output isn't correct
67 Halted 0 ms 0 KB -