Submission #488067

#TimeUsernameProblemLanguageResultExecution timeMemory
488067nickmet2004Chessboard (IZhO18_chessboard)C++11
8 / 100
19 ms3180 KiB
#include<bits/stdc++.h> #define int long long using namespace std; const int N= 1e5 + 5; int n , k; int A[N] , B[N] , C[N] , D[N]; int G[N][2]; int ans = 1e18; void q(int x){ int sz = n / x; for(int i = 0; i < k; ++i){ G[B[i] / x][(A[i] / x) % 2]++; } //for(int i = 0;i < sz; ++i)cout << G[i][0] << " " <<G[i][1]<<endl; int Y = 0 , L = sz / 2 , ok = 0; if(sz % 2 == 1)ok = 1; L += ok; for(int i= 0;i < sz; ++i){ Y += 1ll*L * x * x - G[i][0] + G[i][1]; if(i & 1^1) L -= ok; else L += ok; } //cout << ok << "ok" << endl; //cout << Y << "Y " << endl; ans = min(Y , ans); L = sz/2; Y = 0; for(int i = 0; i < sz; ++i){ Y += G[i][0] + 1ll*L * x * x - G[i][1]; if(i & 1^1) L += ok; else L -= ok; G[i][0] = G[i][1] = 0; } //cout << Y << " Y " << endl; ans = min(Y , ans); //cout << endl; } main (){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for(int i = 0; i < k; ++i){ cin >> A[i] >> B[i] >> C[i] >> D[i]; --A[i] , --B[i] , --C[i] , --D[i]; }//cout << endl; for(int i = 1; i * i <=n; ++i){ if(n % i ==0){ if((n / i) != n)q(n/i); if((n/i) != i)q(i); } } cout << ans; }

Compilation message (stderr)

chessboard.cpp: In function 'void q(long long int)':
chessboard.cpp:20:14: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   20 |         if(i & 1^1) L -= ok;
      |            ~~^~~
chessboard.cpp:30:14: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   30 |         if(i & 1^1) L += ok;
      |            ~~^~~
chessboard.cpp: At global scope:
chessboard.cpp:38:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   38 |  main (){
      |  ^~~~
#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...