제출 #343799

#제출 시각아이디문제언어결과실행 시간메모리
343799_aniChessboard (IZhO18_chessboard)C++17
8 / 100
82 ms2912 KiB
#include <iostream> #include <algorithm> #include <vector> using namespace std; using ll = long long; struct el { int a, b, c, d; }; vector<ll> dv; vector<el> points; ll ans; int prefans(int x, int y, int k, int f) { int ans; int ab = y / k, a; a = (ab + 1) / 2 + 1; a *= k; if (ab % 2 == 0)a += y % k; if (x <= k) ans = x * a; else { int aa = y - a; int q = x / k; ans = aa * (q / 2) * k; ans += a * ((q + 1) / 2) * k; if (q % 2) ans += aa * (x % k); else ans += a * (x % k); } if (f == 1) return ans; else return x * y - ans; } int main() { ll n, k; cin >> n >> k; ans = n * n; for (int i = 1; i < n; i++) if (n % i == 0)dv.push_back(i); for (int i = 0; i < k; i++) { int a, b, c, d; cin >> a >> b >> c >> d; points.push_back({ a,b,c,d }); }/* for (auto p : points) cerr << p.first << ' ' << p.second << '\n';*/ for (ll d : dv) { ll blackans; ll q = n / d; if (q % 2) blackans = (n * n - d * d) / 2 + d * d; else blackans = n * n / 2; ll whiteans = n * n - blackans; for (auto p : points) { blackans = blackans + 2 * prefans(p.a, p.b, d, 1) - p.a * p.b - 2 * prefans(p.c, p.d, d, 1) + p.c * p.d; whiteans = whiteans + 2 * prefans(p.a, p.b, d, 0) - p.a * p.b - 2 * prefans(p.c, p.d, d, 0) + p.c * p.d; } ans = min(ans, min(blackans, whiteans)); } cout << ans; return 0; }
#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...