Submission #90129

#TimeUsernameProblemLanguageResultExecution timeMemory
90129adletChessboard (IZhO18_chessboard)C++17
70 / 100
468 ms2284 KiB
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) using namespace std; typedef long long ll; #define int ll const int N = 1e5 + 5; const ll INF = 1e18; const int mod = 1e9 + 7; const double PI = acos(-1.0); int n, k; ll ans = INF; vector < int > v; int get(int x1, int y1, int d) { x1 /= d; y1 /= d; return ((x1 % 2) == (y1 % 2)); } int x[N], y[N]; main() { cin >> n >> k; for (int i = 1; i <= k; ++i) { int x2, y2; cin >> x[i] >> y[i] >> x2 >> y2; } v.push_back(1); for (int i = 2; i * i <= n; ++i) { if (n % i == 0) { v.push_back(i); if (n / i != i) { v.push_back(n / i); } } } for (int i : v) { int m = n / i, cnt_black = 0, cnt_white = 0; ll black = (((m * m) / 2) + (m * m) % 2) * (i * 1ll * i); ll white = (n * 1ll * n) - black; for (int j = 1; j <= k; ++j) { cnt_black += get(x[j] - 1, y[j] - 1, i); } cnt_white = k - cnt_black; ll x = (black - cnt_black) + cnt_white; ll y = (white - cnt_white) + cnt_black; ans = min(ans, min(x, y)); } cout << ans; }

Compilation message (stderr)

chessboard.cpp:30:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
#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...