답안 #495219

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
495219 2021-12-18T07:00:37 Z pragmatist Chessboard (IZhO18_chessboard) C++14
31 / 100
2000 ms 77052 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;
map<int, bool> c[N]; 

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--;
		}		
		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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14284 KB Output is correct
2 Correct 11 ms 14916 KB Output is correct
3 Correct 9 ms 14912 KB Output is correct
4 Correct 11 ms 14896 KB Output is correct
5 Correct 10 ms 14400 KB Output is correct
6 Correct 12 ms 14916 KB Output is correct
7 Correct 10 ms 14916 KB Output is correct
8 Correct 10 ms 14924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 19000 KB Output is correct
2 Correct 16 ms 15768 KB Output is correct
3 Correct 34 ms 17612 KB Output is correct
4 Correct 34 ms 17992 KB Output is correct
5 Correct 43 ms 18596 KB Output is correct
6 Correct 27 ms 17240 KB Output is correct
7 Correct 11 ms 14924 KB Output is correct
8 Correct 25 ms 17248 KB Output is correct
9 Correct 70 ms 20924 KB Output is correct
10 Correct 48 ms 18248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14668 KB Output is correct
2 Correct 9 ms 14620 KB Output is correct
3 Correct 10 ms 14808 KB Output is correct
4 Correct 11 ms 14800 KB Output is correct
5 Correct 9 ms 14668 KB Output is correct
6 Correct 9 ms 14668 KB Output is correct
7 Correct 10 ms 14792 KB Output is correct
8 Correct 9 ms 14540 KB Output is correct
9 Correct 9 ms 14924 KB Output is correct
10 Correct 11 ms 14404 KB Output is correct
11 Correct 9 ms 14668 KB Output is correct
12 Correct 10 ms 14412 KB Output is correct
13 Correct 11 ms 14668 KB Output is correct
14 Correct 10 ms 14676 KB Output is correct
15 Correct 9 ms 14540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14668 KB Output is correct
2 Correct 9 ms 14620 KB Output is correct
3 Correct 10 ms 14808 KB Output is correct
4 Correct 11 ms 14800 KB Output is correct
5 Correct 9 ms 14668 KB Output is correct
6 Correct 9 ms 14668 KB Output is correct
7 Correct 10 ms 14792 KB Output is correct
8 Correct 9 ms 14540 KB Output is correct
9 Correct 9 ms 14924 KB Output is correct
10 Correct 11 ms 14404 KB Output is correct
11 Correct 9 ms 14668 KB Output is correct
12 Correct 10 ms 14412 KB Output is correct
13 Correct 11 ms 14668 KB Output is correct
14 Correct 10 ms 14676 KB Output is correct
15 Correct 9 ms 14540 KB Output is correct
16 Correct 278 ms 71480 KB Output is correct
17 Correct 67 ms 20432 KB Output is correct
18 Correct 377 ms 77052 KB Output is correct
19 Execution timed out 2044 ms 72852 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 19000 KB Output is correct
2 Correct 16 ms 15768 KB Output is correct
3 Correct 34 ms 17612 KB Output is correct
4 Correct 34 ms 17992 KB Output is correct
5 Correct 43 ms 18596 KB Output is correct
6 Correct 27 ms 17240 KB Output is correct
7 Correct 11 ms 14924 KB Output is correct
8 Correct 25 ms 17248 KB Output is correct
9 Correct 70 ms 20924 KB Output is correct
10 Correct 48 ms 18248 KB Output is correct
11 Correct 11 ms 14668 KB Output is correct
12 Correct 9 ms 14620 KB Output is correct
13 Correct 10 ms 14808 KB Output is correct
14 Correct 11 ms 14800 KB Output is correct
15 Correct 9 ms 14668 KB Output is correct
16 Correct 9 ms 14668 KB Output is correct
17 Correct 10 ms 14792 KB Output is correct
18 Correct 9 ms 14540 KB Output is correct
19 Correct 9 ms 14924 KB Output is correct
20 Correct 11 ms 14404 KB Output is correct
21 Correct 9 ms 14668 KB Output is correct
22 Correct 10 ms 14412 KB Output is correct
23 Correct 11 ms 14668 KB Output is correct
24 Correct 10 ms 14676 KB Output is correct
25 Correct 9 ms 14540 KB Output is correct
26 Correct 278 ms 71480 KB Output is correct
27 Correct 67 ms 20432 KB Output is correct
28 Correct 377 ms 77052 KB Output is correct
29 Execution timed out 2044 ms 72852 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14284 KB Output is correct
2 Correct 11 ms 14916 KB Output is correct
3 Correct 9 ms 14912 KB Output is correct
4 Correct 11 ms 14896 KB Output is correct
5 Correct 10 ms 14400 KB Output is correct
6 Correct 12 ms 14916 KB Output is correct
7 Correct 10 ms 14916 KB Output is correct
8 Correct 10 ms 14924 KB Output is correct
9 Correct 47 ms 19000 KB Output is correct
10 Correct 16 ms 15768 KB Output is correct
11 Correct 34 ms 17612 KB Output is correct
12 Correct 34 ms 17992 KB Output is correct
13 Correct 43 ms 18596 KB Output is correct
14 Correct 27 ms 17240 KB Output is correct
15 Correct 11 ms 14924 KB Output is correct
16 Correct 25 ms 17248 KB Output is correct
17 Correct 70 ms 20924 KB Output is correct
18 Correct 48 ms 18248 KB Output is correct
19 Correct 11 ms 14668 KB Output is correct
20 Correct 9 ms 14620 KB Output is correct
21 Correct 10 ms 14808 KB Output is correct
22 Correct 11 ms 14800 KB Output is correct
23 Correct 9 ms 14668 KB Output is correct
24 Correct 9 ms 14668 KB Output is correct
25 Correct 10 ms 14792 KB Output is correct
26 Correct 9 ms 14540 KB Output is correct
27 Correct 9 ms 14924 KB Output is correct
28 Correct 11 ms 14404 KB Output is correct
29 Correct 9 ms 14668 KB Output is correct
30 Correct 10 ms 14412 KB Output is correct
31 Correct 11 ms 14668 KB Output is correct
32 Correct 10 ms 14676 KB Output is correct
33 Correct 9 ms 14540 KB Output is correct
34 Correct 278 ms 71480 KB Output is correct
35 Correct 67 ms 20432 KB Output is correct
36 Correct 377 ms 77052 KB Output is correct
37 Execution timed out 2044 ms 72852 KB Time limit exceeded
38 Halted 0 ms 0 KB -