Submission #883690

#TimeUsernameProblemLanguageResultExecution timeMemory
883690Sokol080808Chessboard (IZhO18_chessboard)C++17
100 / 100
145 ms8404 KiB
#ifdef ONPC #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> #include <malloc.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") using namespace __gnu_pbds; using namespace std; #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() using ll = long long; using ull = unsigned long long; using ld = long double; template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2>& p) {in >> p.first >> p.second; return in;} template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2>& p) {out << p.first << ' ' << p.second; return out;} template<typename T> istream& operator>>(istream& in, vector<T>& v) {for (auto& x : v) in >> x; return in;} template<typename T> ostream& operator<<(ostream& out, vector<T>& v) {for (auto& x : v) out << x << ' '; return out;} template<typename T> ostream& operator<<(ostream& out, set<T>& v) {for (auto& x : v) out << x << ' '; return out;} template<typename T> ostream& operator<<(ostream& out, multiset<T>& v) {for (auto& x : v) out << x << ' '; return out;} const int MAX_INT = 2147483647; const double pi = acos(-1.0); const int mod = 1e9 + 7; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); struct rect { ll x1, y1, x2, y2; }; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); vector<rect> a; ll n, k; cin >> n >> k; for (int i = 0; i < k; i++) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; a.push_back({x1, y1, x2, y2}); } ll res = n * n; ll wh_cnt[n + 1], bl_cnt[n + 1]; for (int d = 1; d < n; d++) { if (n % d) continue; wh_cnt[0] = 0; bl_cnt[0] = 0; for (int i = 1; i <= n; i++) { int id = (i + d - 1) / d; wh_cnt[i] = wh_cnt[i - 1]; bl_cnt[i] = bl_cnt[i - 1]; if (id % 2) { wh_cnt[i]++; } else { bl_cnt[i]++; } } ll cur = (n / d) * (n / d) / 2 * d * d; for (auto [x1, y1, x2, y2] : a) { cur += (wh_cnt[x2] - wh_cnt[x1 - 1]) * (wh_cnt[y2] - wh_cnt[y1 - 1]) + (bl_cnt[x2] - bl_cnt[x1 - 1]) * (bl_cnt[y2] - bl_cnt[y1 - 1]); cur -= (wh_cnt[x2] - wh_cnt[x1 - 1]) * (bl_cnt[y2] - bl_cnt[y1 - 1]) + (bl_cnt[x2] - bl_cnt[x1 - 1]) * (wh_cnt[y2] - wh_cnt[y1 - 1]); } res = min({res, cur, n * n - cur}); } cout << res << '\n'; 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...