Submission #89353

#TimeUsernameProblemLanguageResultExecution timeMemory
89353RAkhshonChessboard (IZhO18_chessboard)C++14
39 / 100
448 ms9552 KiB
#include<bits/stdc++.h> #define ll long long using namespace std; ll dp[1111][1111]; int main(){ ios_base::sync_with_stdio(0); ll n, k; cin>>n>>k; for( ll i =1; i <= k ; i ++ ){ ll a, b; cin>>a>>b>>a>>b; dp[a][b]=1; } ll ans = 1000000000; for( ll i = 1 ; i*i <= n ; i ++ ){ if( n % i == 0 ){ ll m=i, kolp1=0,kolp2=0 ; for( ll x = 1; x <= n ; x ++ ){ for( ll y = 1; y <= n ; y ++ ){ if( ((x-1)/m)%2==0 && ((y-1)/m)%2 ==0 ) { if( dp[x][y]==0 ) kolp1++; else kolp2++; } if( ((x-1)/m)%2 ==0 && ((y-1)/m)%2 ==1 ) { if( dp[x][y]==1 ) kolp1++; else kolp2++; } if( ((x-1)/m)%2!=0 && ((y-1)/m)%2==0 ) { if( dp[x][y]==1 ) kolp1++; else kolp2++; } if( ((x-1)/m)%2 !=0 && ( (y-1)/m )%2 !=0 ) { if( dp[x][y]==0 ) kolp1++; else kolp2++; } } } ans=min(ans,min(kolp1,kolp2)); m=n/i;kolp1=0;kolp2=0; if( m != n ){ for( ll x = 1; x <= n ; x ++ ){ for( ll y = 1; y <= n ; y ++ ){ if( ((x-1)/m)%2==0 && ((y-1)/m)%2 ==0 ) { if( dp[x][y]==0 ) kolp1++; else kolp2++; } if( ((x-1)/m)%2 ==0 && ((y-1)/m)%2 ==1 ) { if( dp[x][y]==1 ) kolp1++; else kolp2++; } if( ((x-1)/m)%2!=0 && ((y-1)/m)%2==0 ) { if( dp[x][y]==1 ) kolp1++; else kolp2++; } if( ((x-1)/m)%2 !=0 && ( (y-1)/m )%2 !=0 ) { if( dp[x][y]==0 ) kolp1++; else kolp2++; } } } /// cout<<ans<<' '<<kolp1<<' '<<kolp2<<endl; ans=min(ans,min(kolp1,kolp2)); } } } cout<<ans; }
#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...