답안 #168621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168621 2019-12-14T12:06:15 Z MrPlany Chessboard (IZhO18_chessboard) C++17
39 / 100
293 ms 3576 KB
// In the name of God

#include <bits/stdc++.h>
//#include <conio.h>

#define ff first
#define ss second
#define pb push_back
#define pp pop_back
#define mp make_pair
#define db double
#define INF 1000000009
#define ll long long
#define all(a) a.begin(), a.end()
#define iOS ios_base::sync_with_stdio(false)

using namespace std;

const int N = 2e5 + 9, mod = 1e9+7;
int n,k;
struct gr{
	int x1,y1,x2,y2;
};
gr d[N];
int f(int v, int p){
	if(v%p==0) return v;
	return (v/p+1)*p;
}
int ters(int col){
	return (col==1?0:1);
}


ll solve(int p, int col){
	
	ll as_ak = 0 , as_gara = 0;
	
	if( (n/p)%2 == 0 ){
		as_gara = (n*n)/2;
	}
	else{
		
		ll t= (n/p);
		
		as_gara = (t/2)*t + (t-1)/2 + 1;
		as_gara *= (p*p);
		
		if(col == 0) as_gara = (n*n) - as_gara;
		
	}
	
	ll gara = 0 , ak = 0 ;
	for(int i=1;i<=k;i++){
		
		gr a = d[i] , b;
		b = a;
		while(true){
			
			gr c;
			
			c.x2 = f(a.x1,p);
			c.x1 = c.x2 - p + 1;
			
			c.y2 = f(a.y1,p);
			c.y1 = c.y2 - p + 1;
				
			gr e = c;
			e.x1 = max( c.x1 , a.x1 );
			e.y1 = max( c.y1 , a.y1 );
			e.x2 = min( c.x2 , a.x2 );
			e.y2 = min( c.y2 , a.y2 );
			
			ll S = 1LL*abs( e.x2 - e.x1 + 1 ) * abs(e.y2 - e.y1 + 1);
			
			int o1 = f(c.x1,p);
			int o2 = f(c.y1,p);
			
			if( (o1/p)%2 == (o2/p)%2 ){
				if(col == 1) gara+=S;
				else ak+=S;
			}
			else{
				if(ters(col) == 1) gara+=S;
				else ak+=S;
			}
			
			if( e.x2 == a.x2 && e.y2 == a.y2 ) break;
			
			a.y1 = f(a.y1,p) + 1;
			
			if(a.y1 > a.y2) a.x1 = f(a.x1,p) + 1 , a.y1 = b.y1;
			
		}
		
		/*
		int o1 = f(a[i].x1,p);
		int o2 = f(a[i].y1,p);
		if( (o1/p)%2 == (o2/p)%2 ){
			if(col == 1) gara++;
			else ak++;
		}
		else{
			if( ters(col) == 1 ) gara++;
			else ak++;
		}
		*/
	}
	
	//cout << as_gara << " " << " " << ((as_gara - gara) + ak) << " " << p << " " << col << endl;
		// as_garada problema bar.
	return ((as_gara - gara) + ak);
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>k;
	
	for(int i=1;i<=k;i++){
		cin>>d[i].x1>>d[i].y1>>d[i].x2>>d[i].y2;
	}
	ll mn = INF;
	for(int i=1;i<n;i++){
		if(n%i == 0){
			mn = min( mn, solve(i,0) );
			mn = min( mn, solve(i,1) );
		}
	}
	cout <<mn;
	return 0;
}

Compilation message

chessboard.cpp: In function 'long long int solve(int, int)':
chessboard.cpp:36:5: warning: unused variable 'as_ak' [-Wunused-variable]
  ll as_ak = 0 , as_gara = 0;
     ^~~~~
# 결과 실행 시간 메모리 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 Incorrect 33 ms 2908 KB Output isn't correct
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 3 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 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 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 3 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 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 19 ms 1144 KB Output is correct
17 Correct 37 ms 3192 KB Output is correct
18 Correct 62 ms 3444 KB Output is correct
19 Correct 262 ms 3292 KB Output is correct
20 Correct 293 ms 3576 KB Output is correct
21 Correct 35 ms 3064 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 45 ms 1656 KB Output is correct
24 Correct 56 ms 3192 KB Output is correct
25 Correct 10 ms 632 KB Output is correct
26 Correct 36 ms 2168 KB Output is correct
27 Correct 58 ms 2588 KB Output is correct
28 Correct 61 ms 3320 KB Output is correct
29 Correct 16 ms 1400 KB Output is correct
30 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 33 ms 2908 KB Output isn't correct
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 Incorrect 33 ms 2908 KB Output isn't correct
10 Halted 0 ms 0 KB -