Submission #495221

# Submission time Handle Problem Language Result Execution time Memory
495221 2021-12-18T07:02:38 Z pragmatist Chessboard (IZhO18_chessboard) C++14
47 / 100
173 ms 1596 KB
#include <bits/stdc++.h>                            
 
#define pb push_back
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define x first
#define y second
#define int long long
#define nl "\n"
 
using namespace std;

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

const int N = (int)3e5 + 7;
const int M = (int)7e6 + 7;
const ll MOD = (ll)1e9 + 7;                    
const int inf = (int)1e9 + 7;
const ll INF = (ll)3e18 + 7;

pii dir[] = {{-1, -1}, {1, 1}, {-1, 1}, {1, -1}};

int n, k;
bool c[1001][1001];

int f(int x, bool cur) {
    int ans = 0;
	for(int i = 1; i <= n; i += x) {
	    bool ok = cur;
	    for(int j = 1; j <= n; j += x) {
	    	int k = j + x - 1, t = i + x - 1;
	    	for(int l = i; l <= t; ++l) {
	    		for(int r = j; r <= k; ++r) {
	    			if(ok) ans += (c[l][r] == 0);
	    			else ans += (c[l][r] == 1);
	    		}
	    	}
	    	ok ^= 1;
	    }
		cur ^= 1;
	}
	return ans;
}

void solve() {          	             
	cin >> n >> k;
	int a = 0, b = 0;
	for(int i = 1; i <= n; ++i) {
		if(i & 1) a += n / 2, b += (n + 1) / 2;
		else a  += (n + 1) / 2, b += n / 2;
	}
	while(k--) {
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		if(x1 & 1) {
			if(y1 & 1) a++, b--;
			else a--, b++;
		} else {
			if(y1 & 1) a--, b++;
			else a++, b--;
		}
		if(n > 1000) continue;		
		for(int i = x1; i <= x2; ++i) {
			for(int j = y1; j <= y2; ++j) {
				c[i][j] = 1;
			}
		}
	}             
	int ans = min(a, b);
	for(int i = 2; i < n; ++i) {
		if(n % i == 0) {
			ans = min(ans, f(i, 0));
			ans = min(ans, f(i, 1));			
		}
	}
	cout << ans << nl;
}

signed main() {                   
	ios_base::sync_with_stdio(NULL);
    cin.tie(0);
    cout.tie(0);
   	int test = 1;
	//cin >> test;
	for(int i = 1; i <= test; ++i) {
        //cout << "Case " << i << ": ";
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 204 KB Output is correct
2 Correct 5 ms 204 KB Output is correct
3 Correct 11 ms 204 KB Output is correct
4 Correct 13 ms 204 KB Output is correct
5 Correct 17 ms 316 KB Output is correct
6 Correct 11 ms 320 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 11 ms 204 KB Output is correct
9 Correct 25 ms 316 KB Output is correct
10 Correct 16 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 11 ms 1228 KB Output is correct
17 Correct 23 ms 1228 KB Output is correct
18 Correct 28 ms 1228 KB Output is correct
19 Correct 65 ms 1228 KB Output is correct
20 Correct 70 ms 1236 KB Output is correct
21 Correct 23 ms 1228 KB Output is correct
22 Correct 26 ms 1124 KB Output is correct
23 Correct 21 ms 1228 KB Output is correct
24 Correct 24 ms 1228 KB Output is correct
25 Correct 11 ms 1264 KB Output is correct
26 Correct 17 ms 1228 KB Output is correct
27 Correct 25 ms 1228 KB Output is correct
28 Correct 28 ms 1228 KB Output is correct
29 Correct 11 ms 1228 KB Output is correct
30 Correct 7 ms 1228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 204 KB Output is correct
2 Correct 5 ms 204 KB Output is correct
3 Correct 11 ms 204 KB Output is correct
4 Correct 13 ms 204 KB Output is correct
5 Correct 17 ms 316 KB Output is correct
6 Correct 11 ms 320 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 11 ms 204 KB Output is correct
9 Correct 25 ms 316 KB Output is correct
10 Correct 16 ms 320 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 11 ms 1228 KB Output is correct
27 Correct 23 ms 1228 KB Output is correct
28 Correct 28 ms 1228 KB Output is correct
29 Correct 65 ms 1228 KB Output is correct
30 Correct 70 ms 1236 KB Output is correct
31 Correct 23 ms 1228 KB Output is correct
32 Correct 26 ms 1124 KB Output is correct
33 Correct 21 ms 1228 KB Output is correct
34 Correct 24 ms 1228 KB Output is correct
35 Correct 11 ms 1264 KB Output is correct
36 Correct 17 ms 1228 KB Output is correct
37 Correct 25 ms 1228 KB Output is correct
38 Correct 28 ms 1228 KB Output is correct
39 Correct 11 ms 1228 KB Output is correct
40 Correct 7 ms 1228 KB Output is correct
41 Runtime error 173 ms 1596 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 19 ms 204 KB Output is correct
10 Correct 5 ms 204 KB Output is correct
11 Correct 11 ms 204 KB Output is correct
12 Correct 13 ms 204 KB Output is correct
13 Correct 17 ms 316 KB Output is correct
14 Correct 11 ms 320 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 11 ms 204 KB Output is correct
17 Correct 25 ms 316 KB Output is correct
18 Correct 16 ms 320 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 11 ms 1228 KB Output is correct
35 Correct 23 ms 1228 KB Output is correct
36 Correct 28 ms 1228 KB Output is correct
37 Correct 65 ms 1228 KB Output is correct
38 Correct 70 ms 1236 KB Output is correct
39 Correct 23 ms 1228 KB Output is correct
40 Correct 26 ms 1124 KB Output is correct
41 Correct 21 ms 1228 KB Output is correct
42 Correct 24 ms 1228 KB Output is correct
43 Correct 11 ms 1264 KB Output is correct
44 Correct 17 ms 1228 KB Output is correct
45 Correct 25 ms 1228 KB Output is correct
46 Correct 28 ms 1228 KB Output is correct
47 Correct 11 ms 1228 KB Output is correct
48 Correct 7 ms 1228 KB Output is correct
49 Runtime error 173 ms 1596 KB Execution killed with signal 11
50 Halted 0 ms 0 KB -