Submission #99772

#TimeUsernameProblemLanguageResultExecution timeMemory
99772choikiwonChessboard (IZhO18_chessboard)C++17
100 / 100
764 ms4412 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int MN = 100010; int N, K; struct Rect { int r1, c1, r2, c2; }; Rect rect[MN]; int main() { scanf("%d %d", &N, &K); for(int i = 0; i < K; i++) { scanf("%d %d %d %d", &rect[i].r1, &rect[i].c1, &rect[i].r2, &rect[i].c2); rect[i].r1--; rect[i].c1--; rect[i].r2--; rect[i].c2--; } ll mn = 1e18; for(int i = 1; i < N; i++) { if(N % i == 0) { for(int j = 0; j < 2; j++) { int n = N / i; ll tmp = j? (1LL * n * n + 1) / 2 : 1LL * n * n / 2; tmp *= 1LL * i * i; for(int k = 0; k < K; k++) { int rr = min(rect[k].r2 + 1, (rect[k].r1 + i) / i * i); int cc = min(rect[k].c2 + 1, (rect[k].c1 + i) / i * i); int br = (rect[k].r2 - rr + 1) / (2 * i) * i; int bc = (rect[k].c2 - cc + 1) / (2 * i) * i; if((rect[k].r2 - rr + 1) % (2 * i) > i) br += (rect[k].r2 - rr + 1) % (2 * i) - i; if((rect[k].c2 - cc + 1) % (2 * i) > i) bc += (rect[k].c2 - cc + 1) % (2 * i) - i; br += rr - rect[k].r1; bc += cc - rect[k].c1; int wr = rect[k].r2 - rect[k].r1 + 1 - br; int wc = rect[k].c2 - rect[k].c1 + 1 - bc; if(j ^ ((rect[k].r1 / i + rect[k].c1 / i) & 1)) tmp -= 1LL * (br - wr) * (bc - wc); else tmp += 1LL * (br - wr) * (bc - wc); } mn = min(mn, tmp); } } } printf("%lld", mn); }

Compilation message (stderr)

chessboard.cpp: In function 'int main()':
chessboard.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &N, &K);
     ~~~~~^~~~~~~~~~~~~~~~~
chessboard.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d %d", &rect[i].r1, &rect[i].c1, &rect[i].r2, &rect[i].c2);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...