제출 #80973

#제출 시각아이디문제언어결과실행 시간메모리
80973inomChessboard (IZhO18_chessboard)C++14
70 / 100
748 ms61344 KiB
#include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define int long long #define sz(c) (int)(c).size() #define all(c) (c).begin(), (c).end() #define in freopen("A.in", "r", stdin); #define out freopen("A.out", "w", stdout); using namespace std; const int N = 500500; const int INF = 1e15; int TN = 1; int n, k, ans = INF; pair<int, int> a[N]; int get(int a, int b, int c) { a--; b--; a /= c; b /= c; a++; b++; return a + b; } int calc(int x) { if (x == n) { return INF; } // если первая фигня должна быть белой; int res = (((n / x) * (n / x)) / 2) * x * x; for (int i = 1; i <= k; i++) { if (get(a[i].fi, a[i].se, x) % 2 == 0) { res++; } else { res--; } } // иначе; int tmp = (((n / x) * (n / x)) / 2 + (n / x) % 2) * x * x; for (int i = 1; i <= k; i++) { if (get(a[i].fi, a[i].se, x) % 2 == 0) { tmp--; } else { tmp++; } } return min(res, tmp); } void solve() { cin >> n >> k; for (int i = 1; i <= k; i++) { cin >> a[i].fi >> a[i].se >> a[i].fi >> a[i].se; } for (int i = 1; i * i <= n; i++) { if (n % i == 0) { if (i * i == n) { ans = min(ans, calc(i)); } else { ans = min(ans, calc(i)); ans = min(ans, calc(n / i)); } } } cout << ans << "\n"; return; } signed main() { // ios_base::sync_with_stdio(0); // in; out; // cin >> TN; while (TN--) solve(); 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...