제출 #551892

#제출 시각아이디문제언어결과실행 시간메모리
551892sidonChessboard (IZhO18_chessboard)C++17
100 / 100
388 ms1832 KiB
#include <bits/stdc++.h> using namespace std; #define ll int64_t int32_t main() { int N, K; cin >> N >> K; ll ans = ll(N) * N; array<int, 4> a[K]; for(auto &[i, j, k, l] : a) cin >> i >> j >> k >> l; for(int s = 1; s < N; ++s) if(!(N % s)) { #define c(V) (s * ((V) / (2 * s)) + min(s, (V) % (2 * s))) ll cost = ll(c(N)) * (N - c(N)) + ll(c(N)) * (N - c(N)); for(auto [i, j, k, l] : a) { ll u = k - i + 1, x = c(k) - c(i - 1); ll v = l - j + 1, y = c(l) - c(j - 1); cost += 2 * (x * y + (u - x) * (v - y)) - u * v; } ans = min(ans, min(cost, ll(N) * N - cost)); } cout << ans; }
#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...