Submission #172752

#TimeUsernameProblemLanguageResultExecution timeMemory
172752muhammad_hokimiyonChessboard (IZhO18_chessboard)C++14
70 / 100
693 ms7804 KiB
#include <bits/stdc++.h> //#pragma GCC optimize("Ofast") #define fi first #define se second #define ll long long using namespace std; const int N = 2e5 + 7; const int M = 23; const int mod = 998244353; ll n,k; ll A[N]; ll B[N]; ll C[N]; ll D[N]; void solve1() { cin >> n >> k; vector < ll > div; for( int i = 1; i < n; i++ ){ if( n % i == 0 )div.push_back(i); } for( int i = 0; i < k; i++ ){ cin >> A[i] >> B[i] >> C[i] >> D[i]; } ll ans = 1e14; for( int i = 0; i < (int)div.size(); i++ ){ ll nn = n / div[i]; ll B1 = (nn + 1) / 2; ll B2 = nn / 2; B1 *= div[i] * div[i]; B2 *= div[i] * div[i]; B1 *= (nn + 1) / 2; B2 *= nn / 2; B1 += B2; ll B3 = (nn) / 2; ll B4 = (nn + 1) / 2; B3 *= div[i] * div[i]; B4 *= div[i] * div[i]; B3 *= (nn + 1) / 2; B4 *= (nn) / 2; B3 += B4; vector < ll > w(k , 0); vector < ll > b(k , 0); for( int j = 0; j < k; j++ ){ //ll x = f(C[j] , D[j] , div[i]) - f(C[j] , B[j] - 1 , div[i]) - //f(A[j] - 1, D[j] , div[i]) + f(A[j] - 1 , B[j] - 1 , div[i]); //ll y = (C[j] - A[j]) * (D[j] - B[j]); ll x = 0; ll y = 1; if( (A[j] - 1) / div[i] % 2 == 0 && (B[j] - 1) / div[i] % 2 == 0 ){ x = 1; } if( (A[j] - 1) / div[i] % 2 == 1 && (B[j] - 1) / div[i] % 2 == 1 ){ x = 1; } w[j] = y - x; b[j] = x; } ll x = 0; ll y = 0; //cout << B1 << " " << B3 << " "; for( int j = 0; j < k; j++ ){ B1 -= b[j]; x += 1 - b[j]; y += b[j]; B3 -= 1 - b[j]; } //cout << B1 + x << " " << B3 + y << " " << div[i] << "\n"; ans = min(ans , B1 + x); ans = min(ans , B3 + y); } cout << ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen( "input.txt" , "r" , stdin ); //freopen( "output.txt" , "w" , stdout ); int cghf = 1;//cin >> cghf; while( cghf-- ){ solve1(); } }
#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...