Submission #167805

# Submission time Handle Problem Language Result Execution time Memory
167805 2019-12-10T08:02:07 Z abil Chessboard (IZhO18_chessboard) C++14
16 / 100
45 ms 3192 KB
#include <bits/stdc++.h>

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define all(s) s.begin(),s.end()
#define int long long

using namespace std;

const int N = (1e5 + 12);
const int mod = (1e9 + 7);
const int INF = (0x3f3f3f3f);

int ans = 1e16;
int n, k, x[2][N], y[2][N];

void calc(int div){
	int bl = n / div, cnt = 0, x1, y1, cnt1 = 0;
	if(bl & 1){
		cnt += div * div * ((bl + 1) / 2) * ((bl + 1) / 2);
		cnt += div * div * (bl / 2) * (bl / 2);
		cnt1 = n * n - cnt;
		for(int i = 1;i <= k; i++){
			x1 = x[0][i];
			y1 = y[0][i];
			x1 = (x1 + bl - 1) / bl;
			y1 = (y1 + bl - 1) / bl;
			if((x1 + y1) % 2 == 0){
				cnt--;
				cnt1++;
			}
			else{
				cnt++;
				cnt1--;
			}
		}
		ans = min(ans, cnt);
		ans = min(ans, cnt1);
	}
	else{
		cnt += div * div * (bl / 2) * bl;
		cnt1 = n * n - cnt;
		for(int i = 1;i <= k; i++){
			x1 = x[0][i];
			y1 = y[0][i];
			x1 = (x1 + bl - 1) / bl;
			y1 = (y1 + bl - 1) / bl;
			if((x1 + y1) % 2 == 0){
				cnt--;
				cnt1++;
			}
			else{
				cnt++;
				cnt1--;
			}
		}
		ans = min(ans, cnt);
		ans = min(ans, cnt1);
	}
}
main()
{
	cin >> n >> k;
	for(int i = 1;i <= k; i++){
		scanf("%lld%lld%lld%lld", &x[0][i], &y[0][i], &x[1][i], &y[1][i]);
	}
	if(n % 2 == 1){
		int x1, y1;
		int cnt = n * n / 2ll + 1ll, cnt1 = n * n / 2ll;
		for(int i = 1;i <= k; i++){
			x1 = x[0][i];
			y1 = y[0][i];
			if((x1 + y1) % 2 == 0){
				cnt--;
				cnt1++;
			}
			else{
				cnt++;
				cnt1--;
			}
		}
		ans = min(ans, cnt);
		ans = min(ans, cnt1);
	}
	else{
		int x1, y1;
		int cnt = n * n / 2ll, cnt1 = n * n / 2ll;
		for(int i = 1;i <= k; i++){
			x1 = x[0][i];
			y1 = y[0][i];
			if((x1 + y1) % 2 == 0){
				cnt--;
				cnt1++;
			}
			else{
				cnt++;
				cnt1--;
			}
		}
		ans = min(ans, cnt);
		ans = min(ans, cnt1);
	}
	for(int i = 2;i * i < n; i++){
		if(n % i == 0){
			calc(i);
			calc(n / i);
		}
	}
	cout << ans;
}

Compilation message

chessboard.cpp:63:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
chessboard.cpp: In function 'int main()':
chessboard.cpp:67:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld%lld", &x[0][i], &y[0][i], &x[1][i], &y[1][i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory 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 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 2428 KB Output is correct
2 Correct 9 ms 888 KB Output is correct
3 Correct 21 ms 1528 KB Output is correct
4 Correct 22 ms 1784 KB Output is correct
5 Correct 27 ms 2040 KB Output is correct
6 Correct 18 ms 1404 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 18 ms 1504 KB Output is correct
9 Correct 45 ms 3192 KB Output is correct
10 Correct 26 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 2428 KB Output is correct
2 Correct 9 ms 888 KB Output is correct
3 Correct 21 ms 1528 KB Output is correct
4 Correct 22 ms 1784 KB Output is correct
5 Correct 27 ms 2040 KB Output is correct
6 Correct 18 ms 1404 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 18 ms 1504 KB Output is correct
9 Correct 45 ms 3192 KB Output is correct
10 Correct 26 ms 1912 KB Output is correct
11 Incorrect 2 ms 376 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 31 ms 2428 KB Output is correct
10 Correct 9 ms 888 KB Output is correct
11 Correct 21 ms 1528 KB Output is correct
12 Correct 22 ms 1784 KB Output is correct
13 Correct 27 ms 2040 KB Output is correct
14 Correct 18 ms 1404 KB Output is correct
15 Correct 5 ms 632 KB Output is correct
16 Correct 18 ms 1504 KB Output is correct
17 Correct 45 ms 3192 KB Output is correct
18 Correct 26 ms 1912 KB Output is correct
19 Incorrect 2 ms 376 KB Output isn't correct
20 Halted 0 ms 0 KB -