Submission #942936

# Submission time Handle Problem Language Result Execution time Memory
942936 2024-03-11T07:08:07 Z Teemka Chessboard (IZhO18_chessboard) C++17
39 / 100
60 ms 6612 KB
#include "bits/stdc++.h" 
#define F first
#define S second
#define ALL(a) a.begin() , a.end()

#ifndef ONLINE_JUDGE
#define OK  cout << __LINE__ << "| "<< "---------------------------OK-----------------------" << endl;
#define deb(x) cout << __LINE__ << "| "<< #x  << " = " << x << endl;
#else
#define OK  
#define deb(x) 
#endif
 
typedef long double ld;
typedef long long ll;
#define int ll
using namespace std ;
const ll N = 1e3 + 7 ;	
const ll INF = 1e9;
const ll mod = 1e9 + 7 ;
const double eps = 1e-9 ;
const int dx[]  = { 0 , 0 , 1 , -1, 1 , -1 , 1 , -1} , dy[] = {1 , -1 , 0 , 0 , 1 , 1, -1 , -1}  ;
int n, k;
struct query{
	int x1, x2 ,y1 ,y2;
	query(int _x1, int _x2 ,int _y1, int _y2){
		x1 = _x2, x2 = _x2, y1 = _y1, y2 = _y2;
	}
};
vector<query> vec;
void test_solve(int test_index){
	cin >> n >> k;
	for(int i = 1; i <= k; i++){
		int x1, x2, y1, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		vec.push_back(query(x1 , x2 ,y1 ,y2));
	}
	ll ans = INF;
	for(int i = 1; i < n; i++){
		if(n % i)
			continue;
		ll cnt[2] = {0 , 0};
		for(auto [x1 ,x2 ,y1, y2] : vec){
			int dnt[2] = {0 , 0};
			for(int j = x1; j <= x2; j++){
				if((j - 1) / i % 2){
					dnt[1]++;
				}	
				else{
					dnt[0]++;
				}
			}
			for(int j = y1; j <= y2; j++){
				if((j - 1) / i % 2){
					cnt[1] += dnt[0];
					cnt[0] += dnt[1];
				}
				else{
					cnt[0] += dnt[0];
					cnt[1] += dnt[1];
				}
			}
		}
		int d = n / i , less , big;
		if(d % 2){
			less = (d * d - 1) / 2 * (i * i);
			big = less + i * i;
		}
		else{
			less = (d * d) / 2 * (i * i);
			big = less;
		}
		// deb(big);
		// deb(less);
		// deb(cnt[0]);
		// deb(cnt[1]);
		// deb(i);
		ans = min({ans, (big - cnt[0]) + cnt[1] , cnt[0] + (less- cnt[1])});
	}
	cout << ans << endl;
}

signed main(){
	ios_base::sync_with_stdio(false) ;
    cin.tie(0) ;
    cout.tie(0); 
	int test = 1;
	//cin >> test ;
	for(int i = 1 ;  i <= test ; i++){
 //		cout << "Case " << i << ": " ; 
		test_solve(i) ;
	}
  	return 0;	
}        
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 2520 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 7 ms 1500 KB Output is correct
17 Correct 20 ms 6612 KB Output is correct
18 Correct 25 ms 6096 KB Output is correct
19 Correct 55 ms 6612 KB Output is correct
20 Correct 60 ms 5076 KB Output is correct
21 Correct 18 ms 5844 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 14 ms 2552 KB Output is correct
24 Correct 22 ms 4816 KB Output is correct
25 Correct 3 ms 992 KB Output is correct
26 Correct 14 ms 3544 KB Output is correct
27 Correct 20 ms 5588 KB Output is correct
28 Correct 25 ms 6356 KB Output is correct
29 Correct 8 ms 2520 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 2520 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 17 ms 2520 KB Output isn't correct
10 Halted 0 ms 0 KB -