답안 #1107767

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1107767 2024-11-02T05:07:24 Z Muhammet Chessboard (IZhO18_chessboard) C++17
컴파일 오류
0 ms 0 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 <vector <int>> a(n+1, vector <int> (n+1,0)), dp(n+1, vector <int> (n+1,0));
	vector <int> x1(k+1), y1(k+1), x2(k+1), y2(k+1);
	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;
		bool tr = 1;
		for(int i = 1; i <= n; i += x){
			int cnt = 0;
			for(int j = 1; j <= n; j += x){
				// cout << i << ' ' << j << " " << (dp[i+x-1][j+x-1] - dp[i-1][j+x-1] - dp[i+x-1][j-1] + dp[i-1][j-1]) << "\n";
				cnt++;
				if(cnt % 2 == tr){
					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]);
				}
			}
			tr = (1-tr);
		}
		ans = min(ans,y);
		if((n / x) % 2 == 0){
			y = 0;
			tr = 0;
			for(int i = 1; i <= n; i += x){
				int cnt = 0;
				for(int j = 1; j <= n; j += x){
					// cout << i << ' ' << j << " " << (dp[i+x-1][j+x-1] - dp[i-1][j+x-1] - dp[i+x-1][j-1] + dp[i-1][j-1]) << "\n";
					cnt++;
					if(cnt % 2 == tr){
						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]);
					}
				}
				tr = (1-tr);#include <bits/stdc++.h>

using namespace std;

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

	int n, k;
	cin >> n >> k;
	vector <vector <int>> a(n+1, vector <int> (n+1,0)), dp(n+1, vector <int> (n+1,0));
	vector <int> x1(k+1), y1(k+1), x2(k+1), y2(k+1);
	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;
		bool tr = 1;
		for(int i = 1; i <= n; i += x){
			int cnt = 0;
			for(int j = 1; j <= n; j += x){
				// cout << i << ' ' << j << " " << (dp[i+x-1][j+x-1] - dp[i-1][j+x-1] - dp[i+x-1][j-1] + dp[i-1][j-1]) << "\n";
				cnt++;
				if(cnt % 2 == tr){
					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]);
				}
			}
			tr = (1-tr);
		}
		ans = min(ans,y);
		if((n / x) % 2 == 0){
			y = 0;
			tr = 0;
			for(int i = 1; i <= n; i += x){
				int cnt = 0;
				for(int j = 1; j <= n; j += x){
					// cout << i << ' ' << j << " " << (dp[i+x-1][j+x-1] - dp[i-1][j+x-1] - dp[i+x-1][j-1] + dp[i-1][j-1]) << "\n";
					cnt++;
					if(cnt % 2 == tr){
						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]);
					}
				}
				tr = (1-tr);
			}
			ans = min(ans,y);
		}
	}
	cout << ans;
}
			}
			ans = min(ans,y);
		}
	}
	cout << ans;
}

Compilation message

chessboard.cpp:65:17: error: stray '#' in program
   65 |     tr = (1-tr);#include <bits/stdc++.h>
      |                 ^
chessboard.cpp: In function 'int main()':
chessboard.cpp:65:18: error: 'include' was not declared in this scope
   65 |     tr = (1-tr);#include <bits/stdc++.h>
      |                  ^~~~~~~
chessboard.cpp:65:27: error: 'bits' was not declared in this scope
   65 |     tr = (1-tr);#include <bits/stdc++.h>
      |                           ^~~~
chessboard.cpp:65:32: error: 'stdc' was not declared in this scope; did you mean 'std'?
   65 |     tr = (1-tr);#include <bits/stdc++.h>
      |                                ^~~~
      |                                std
chessboard.cpp:67:1: error: expected primary-expression before 'using'
   67 | using namespace std;
      | ^~~~~
chessboard.cpp:69:11: error: a function-definition is not allowed here before '{' token
   69 | int main(){
      |           ^