Submission #942931

# Submission time Handle Problem Language Result Execution time Memory
942931 2024-03-11T07:06:09 Z Teemka Chessboard (IZhO18_chessboard) C++17
39 / 100
60 ms 3800 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;
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));
	}
	int ans = INF;
	for(int i = 1; i < n; i++){
		if(n % i)
			continue;
		int 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 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 0 ms 456 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 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 1500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 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 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 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 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 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 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 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 1 ms 348 KB Output is correct
16 Correct 11 ms 1504 KB Output is correct
17 Correct 20 ms 3800 KB Output is correct
18 Correct 25 ms 3800 KB Output is correct
19 Correct 54 ms 3800 KB Output is correct
20 Correct 60 ms 3800 KB Output is correct
21 Correct 19 ms 3796 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 14 ms 2268 KB Output is correct
24 Correct 27 ms 3668 KB Output is correct
25 Correct 3 ms 860 KB Output is correct
26 Correct 15 ms 2268 KB Output is correct
27 Correct 20 ms 3544 KB Output is correct
28 Correct 24 ms 3800 KB Output is correct
29 Correct 8 ms 2012 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 1500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 0 ms 456 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 17 ms 1500 KB Output isn't correct
10 Halted 0 ms 0 KB -