Submission #1108501

#TimeUsernameProblemLanguageResultExecution timeMemory
1108501KasymKChessboard (IZhO18_chessboard)C++17
100 / 100
396 ms6760 KiB
#include "bits/stdc++.h" using namespace std; #define ff first #define ss second #define all(v) v.begin(), v.end() #define ll long long #define pb push_back #define pii pair<int, int> #define pli pair<ll, int> #define pll pair<ll, ll> #define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i) #define wr puts("----------------") template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} const ll INF = 1e18; #define int long long using node = tuple<int, int, int, int>; int answer = INF; vector<node> adj; int n, kk; int f(int x, int y, int xx){ int sm = 0, _x = (x/xx)*xx, _y = (y/xx)*xx; if((_x/xx+_y/xx)&1){ sm += ((_x/xx)*(_y/xx))/2*(xx*xx); sm += (_y/xx+1)/2*(x-_x)*xx; sm += (_x/xx+1)/2*(y-_y)*xx; } else{ sm += ((_x/xx)*(_y /xx)+1)/2*(xx*xx); sm += (_y/xx)/2*(x-_x)*xx; sm += ((_x/xx))/2*(y-_y)*xx; sm += (x-_x)*(y-_y); } return sm; } void solve(int x){ int ans = n*n-f(n, n, x); for(auto xx : adj){ int a, b, c, d; tie(a, b, c, d) = xx; int w = f(c, d, x)+f(a-1, b-1, x)-f(c, b-1, x)-f(a-1, d, x); ans += w, ans -= (c-a+1)*(d-b+1)-w; } umin(answer, ans); umin(answer, n*n-ans); } signed main(){ // freopen("file.txt", "r", stdin); scanf("%lld%lld", &n, &kk); bool done = 1; for(int i = 1; i <= kk; ++i){ int a, b, c, d; scanf("%lld%lld%lld%lld", &a, &b, &c, &d); adj.pb({a, b, c, d}); done |= (a==c and b==d); } assert(done); for(int i = 1; i*i <= n; ++i){ if(n%i==0){ solve(i); if(i!=n/i and i>1) solve(n/i); } } printf("%lld\n", answer); return 0; }

Compilation message (stderr)

chessboard.cpp: In function 'int main()':
chessboard.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |     scanf("%lld%lld", &n, &kk);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
chessboard.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...