답안 #1107912

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1107912 2024-11-02T10:11:10 Z Muhammet Chessboard (IZhO18_chessboard) C++17
39 / 100
53 ms 9808 KB
#include <bits/stdc++.h>

using namespace std;

int main(){
	ios::sync_with_stdio(false); cin.tie(nullptr);

	int n, k;
	cin >> n >> k;
	vector <int> x1(k+1), y1(k+1), x2(k+1), y2(k+1);
	if(n > 1000){
		int cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0;
		for(int i = 1; i <= k; i++){
			cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
			if(x1[i] % 2 == 1){
				if(y1[i] % 2 == 1) cnt1++;
				else cnt2++;
			}
			if(x1[i] % 2 == 0){
				if(y1[i] % 2 == 1) cnt3++;
				else cnt4++;
			}
		}
		int ans = ((((n+1)/2) * ((n+1)/2)) - cnt1) + ((((n)/2) * ((n)/2)) - cnt4) + (k-(cnt4+cnt1));
		ans = min(((((n)/2) * ((n)/2)) - cnt3) + ((((n+1)/2) * ((n+1)/2)) - cnt2) + (k-(cnt2+cnt3)), ans);
		cout << ans;
		return 0;
	}
	vector <vector <int>> a(n+1, vector <int> (n+1,0)), dp(n+1, vector <int> (n+1,0));
	for(int i = 1; i <= k; i++){
		cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
		for(int i1 = x1[i]; i1 <= x2[i]; i1++){
			for(int j1 = y1[i]; j1 <= y2[i]; j1++){
				a[i1][j1] = 1;
			}
		}
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + a[i][j]);
		}
	}
	vector <int> v;
	for(int i = 1; i < n; i++){
		if(n % i == 0){
			v.push_back(i);
		}
	}
	int ans = n*n;
	for(auto x : v){
		int y = 0, y1 = 0;
		bool tr = 1;
		for(int i = 1; i <= n; i += x){
			int cnt = 0;
			for(int j = 1; j <= n; j += x){
				cnt++;
				if(cnt % 2 == tr){
					y1 += (dp[i+x-1][j+x-1] - dp[i-1][j+x-1] - dp[i+x-1][j-1] + dp[i-1][j-1]);
					y += ((x*x) - (dp[i+x-1][j+x-1] - dp[i-1][j+x-1] - dp[i+x-1][j-1] + dp[i-1][j-1]));
				}
				else {
					y += (dp[i+x-1][j+x-1] - dp[i-1][j+x-1] - dp[i+x-1][j-1] + dp[i-1][j-1]);
					y1 += ((x*x) - (dp[i+x-1][j+x-1] - dp[i-1][j+x-1] - dp[i+x-1][j-1] + dp[i-1][j-1]));
				}
			}
			tr = (1-tr);
		}
		ans = min(ans,y);
		ans = min(ans,y1);
	}
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 508 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 1360 KB Output is correct
2 Incorrect 4 ms 592 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 504 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 480 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 504 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 504 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 480 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 504 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 13 ms 8184 KB Output is correct
17 Correct 29 ms 9552 KB Output is correct
18 Correct 30 ms 9808 KB Output is correct
19 Correct 38 ms 9040 KB Output is correct
20 Correct 29 ms 9316 KB Output is correct
21 Correct 47 ms 9720 KB Output is correct
22 Correct 9 ms 8272 KB Output is correct
23 Correct 31 ms 8528 KB Output is correct
24 Correct 31 ms 9552 KB Output is correct
25 Correct 15 ms 8016 KB Output is correct
26 Correct 19 ms 8528 KB Output is correct
27 Correct 36 ms 8784 KB Output is correct
28 Correct 53 ms 9040 KB Output is correct
29 Correct 16 ms 8272 KB Output is correct
30 Correct 13 ms 8016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 1360 KB Output is correct
2 Incorrect 4 ms 592 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 508 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 15 ms 1360 KB Output is correct
10 Incorrect 4 ms 592 KB Output isn't correct
11 Halted 0 ms 0 KB -