제출 #43750

#제출 시각아이디문제언어결과실행 시간메모리
43750nickyrioChessboard (IZhO18_chessboard)C++14
70 / 100
2097 ms262144 KiB
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define FORD(i, a, b) for (int i = (a); i >= (b); --i) #define REP(i, a) for (int i = 0; i < (a); ++i) #define DEBUG(x) { cerr << #x << '=' << x << endl; } #define Arr(a, l, r) { cerr << #a << " = {"; FOR(_, l, r) cerr << ' ' << a[_]; cerr << "}\n"; } #define N 100100 #define pp pair<int, int> #define endl '\n' #define IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define taskname "" #define bit(S, i) (((S) >> (i)) & 1) using namespace std; int n, k, xx1[N], xx2[N], xy1[N], xy2[N]; pp operator+ (pp a, pp b) { return pp(a.first + b.first, a.second + b.second); } pp cal(int l, int x1, int y1, int x2, int y2) { if (x2 < x1 || y2 < y1) return pp(0, 0); int mx1 = (x1 - 1 + l) / l * l, mx2 = (x2 + 1) / l * l - 1; int my1 = (y1 - 1 + l) / l * l, my2 = (y2 + 1) / l * l - 1; if (x1 / l == x2 / l) { if (y1 / l == y2 / l) { if (((x1 / l) % 2) == (y1 / l) % 2) return pp(0, 1ll * (x2 - x1 + 1) * (y2 - y1 + 1)); return pp(1ll * (x2 - x1 + 1) * (y2 - y1 + 1), 0); } if (my1 == y1 && my2 == y2) { int sz = (y2 + 1 - y1) / l; if (sz % 2 == 0) return pp(0, 0); if (((x1 / l) % 2) == (y1 / l) % 2) return pp(0, 1ll * (x2 - x1 + 1) * l); return pp(1ll * (x2 - x1 + 1) * l, 0); } return cal(l, x1, y1, x2, my1 - 1) + cal(l, x1, my1, x2, my2) + cal(l, x1, my2 + 1, x2, y2); } if (mx1 == x1 && mx2 == x2 && y1 == my1 && y2 == my2) { int sz = (y2 + 1 - y1) / l * (x2 + 1 - x1) / l; if (sz % 2 == 0) return pp(0, 0); if (((x1 / l) % 2) == (y1 / l) % 2) return pp(0, 1ll * l * l); return pp(1ll * l * l, 0); } return cal(l, x1, y1, mx1 - 1, y2) + cal(l, mx1, y1, mx2, y2) + cal(l, mx2 + 1, y1, x2, y2); } long long solve(int l) {// color = 0 -> Top-left is black long long ans1 = ((1ll * (n / l) * (n / l) + 1) / 2) * l * l; long long ans2 = ((1ll * (n / l) * (n / l)) / 2) * l * l; /*REP(i, k) { if (color ^ (((xx1[i] / l) % 2) == (xy1[i] / l) % 2)) ans--; else ans++; }*/ REP(i, k) { pp t = cal(l, xx1[i], xy1[i], xx2[i], xy2[i]); ans1 += t.first - t.second; ans2 += t.second - t.first; } return min(ans1, ans2); } int main() { #ifdef NERO freopen("test.inp","r",stdin); freopen("test.out","w",stdout); clock_t stime = clock(); #endif //NERO scanf("%d %d", &n, &k); long long ans = 1e10; REP(i, k) scanf("%d %d %d %d", &xx1[i], &xy1[i], &xx2[i], &xy2[i]); REP(i, k) xx1[i]--,xx2[i]--,xy1[i]--,xy2[i]--; ans = solve(1); FOR(i, 2, sqrt(n)) if (n % i == 0) { ans = min(ans, min(solve(i), solve(n / i))); } printf("%lld", ans); #ifdef NERO clock_t etime = clock(); cerr << "Execution time: " << (etime - stime) / CLOCKS_PER_SEC * 1000 << " ms."; #endif // NERO }

컴파일 시 표준 에러 (stderr) 메시지

chessboard.cpp: In function 'int main()':
chessboard.cpp:68:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &k);
                           ^
chessboard.cpp:70:71: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     REP(i, k) scanf("%d %d %d %d", &xx1[i], &xy1[i], &xx2[i], &xy2[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...