제출 #673545

#제출 시각아이디문제언어결과실행 시간메모리
673545CutebolChessboard (IZhO18_chessboard)C++17
70 / 100
405 ms5880 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
#define Scaramouche ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0);
#define int long long
#define itn int
#define endl "\n"
#define ff first
#define ss second
   
const int N = 2e5 + 5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e12 ;

int n , k , m , sum , ans = inf ;
int x[N] , y[N] ;
vector <pair <int,int>> vec ;

void chk ( int a ){
	
	int cur = ( (n / a) * (n / a) + 1 ) / 2 * a * a , cnt = 0 ;
	for ( auto i : vec ){
		int x = i.ff/a , y = i.ss/a ;
		if ( (x + y) % 2 == 0 ) cur -- ;
		else cnt ++ ;
	}
	ans = min ( ans , cur + cnt ) ;
	cur = ( (n / a) * (n / a) ) / 2 * a * a , cnt = 0 ;
	for ( auto i : vec ){
		int x = i.ff/a , y = i.ss/a ;
		if ( (x + y) % 2 ) cur -- ;
		else cnt ++ ;
	}
	ans = min ( ans , cnt + cur ) ;
}

void solve(){
	
	cin >> n >> m ;
	for ( int i = 0 ; i < m ; i ++ ){
		cin >> x[i] >> y[i] >> x[i] >> y[i] ;
		vec.push_back({--x[i],--y[i]}) ;
	}
	chk(1) ;
	for ( int i = 2 ; i*i <= n ; i ++ ){
		if ( n % i == 0 ){
			chk(n/i) ;
			chk(i) ;
		}
	}
	cout << ans ;
}
 
signed main(){
//  fopn("blocks") ;
    Scaramouche ;
    int t = 1 ;
//    	cin >> t ;
    while ( t -- ) solve() ; 
}

컴파일 시 표준 에러 (stderr) 메시지

chessboard.cpp: In function 'void fopn(std::string)':
chessboard.cpp:5:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
chessboard.cpp:5:72: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...