Submission #151528

#TimeUsernameProblemLanguageResultExecution timeMemory
151528nvmdavaChessboard (IZhO18_chessboard)C++17
100 / 100
701 ms2808 KiB
#include <bits/stdc++.h> using namespace std; #define N 200002 #define ff first #define ss second #define ll long long vector<ll> di = {1}; ll dif[200005], res = 1e12; inline ll find(ll x, ll d){ return x / (2 * d) * d + min(x % (2 * d), d); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll n, k, ox, ex, oy, ey; cin>>n>>k; for(ll i = 2; i * i <= n; i++){ if(n % i == 0){ di.push_back(i); if(i * i != n) di.push_back(n / i); } } for(ll i = 0; i < di.size(); i++) dif[i] = n * n - n * n / (di[i] * di[i]) / 2 * (di[i] * di[i]); while(k--){ ll x1, x2, y1, y2; cin>>x1>>y1>>x2>>y2; x1--; y1--; for(ll i = 0; i < di.size(); i++){ ex = find(x2, di[i]) - find(x1, di[i]); ox = x2 - x1 - ex; ey = find(y2, di[i]) - find(y1, di[i]); oy = y2 - y1 - ey; dif[i] += ex * oy + ey * ox - ex * ey - ox * oy; } } for(ll i = 0; i < di.size(); i++) res = min(res, min(dif[i], n * n - dif[i])); cout<<res; }

Compilation message (stderr)

chessboard.cpp: In function 'int main()':
chessboard.cpp:31:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(ll i = 0; i < di.size(); i++)
                ~~^~~~~~~~~~~
chessboard.cpp:38:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(ll i = 0; i < di.size(); i++){
                 ~~^~~~~~~~~~~
chessboard.cpp:47:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(ll i = 0; i < di.size(); i++)
                ~~^~~~~~~~~~~
#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...