답안 #171648

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
171648 2019-12-29T13:37:26 Z Lightning Chessboard (IZhO18_chessboard) C++14
39 / 100
179 ms 9720 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 int ll

const int N = 2000;
const int INF = 2e9 + 5;

int sc[N][N];

void solve1(int n, int k) {
	for(int it = 1; it <= k; ++it) { 
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		//swap(x1, y1);
		//swap(x2, y2);
		for(int i = x1; i <= x2; ++i) {
			++sc[i][y1];
		}
		for(int i = x1; i <= x2; ++i) {
			--sc[i][y2 + 1];
		}
	}
	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 res1 = 0, res2 = 0;
		for(int i = 1; i <= n; ++i) {
			int cur = 0;
			bool vs = ((((i - 1) / di) & 1) ^ 1);
			for(int j = 1; j <= n; ++j) {
				cur += sc[i][j];
				// (cur > 0) -> black : white
				if(cur > 0) {
					if((((j - 1) / di) & 1) ^ vs) ++res1;
					else ++ res2;	
				} else {
					if((((j - 1) / di) & 1) ^ vs) ++res2;
					else ++res1;
				}
			}
		}
		/*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) cout << 1;
				else cout << 2;	
			}
			cout << '\n';
		}
		cout << '\n';*/
		ans = min(ans, min(res1, res2));
	}
	cout << ans;
}

/*void solve2(int n, int k) {
	
}*/

int 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!	
*/
# 결과 실행 시간 메모리 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 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
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 3 ms 632 KB Output is correct
4 Correct 3 ms 632 KB Output is correct
5 Correct 3 ms 632 KB Output is correct
6 Correct 2 ms 636 KB Output is correct
7 Correct 3 ms 648 KB Output is correct
8 Correct 3 ms 632 KB Output is correct
9 Correct 2 ms 760 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 3 ms 632 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 3 ms 632 KB Output is correct
14 Correct 3 ms 684 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 3 ms 632 KB Output is correct
4 Correct 3 ms 632 KB Output is correct
5 Correct 3 ms 632 KB Output is correct
6 Correct 2 ms 636 KB Output is correct
7 Correct 3 ms 648 KB Output is correct
8 Correct 3 ms 632 KB Output is correct
9 Correct 2 ms 760 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 3 ms 632 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 3 ms 632 KB Output is correct
14 Correct 3 ms 684 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 30 ms 7928 KB Output is correct
17 Correct 48 ms 9464 KB Output is correct
18 Correct 64 ms 9720 KB Output is correct
19 Correct 171 ms 9308 KB Output is correct
20 Correct 179 ms 9336 KB Output is correct
21 Correct 47 ms 9592 KB Output is correct
22 Correct 66 ms 1912 KB Output is correct
23 Correct 54 ms 8440 KB Output is correct
24 Correct 62 ms 9552 KB Output is correct
25 Correct 38 ms 7160 KB Output is correct
26 Correct 45 ms 8620 KB Output is correct
27 Correct 58 ms 8824 KB Output is correct
28 Correct 60 ms 9208 KB Output is correct
29 Correct 25 ms 8312 KB Output is correct
30 Correct 19 ms 5624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 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 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Halted 0 ms 0 KB -