Submission #883690

# Submission time Handle Problem Language Result Execution time Memory
883690 2023-12-05T17:52:42 Z Sokol080808 Chessboard (IZhO18_chessboard) C++17
100 / 100
145 ms 8404 KB
#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 time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 4816 KB Output is correct
2 Correct 5 ms 1756 KB Output is correct
3 Correct 12 ms 3944 KB Output is correct
4 Correct 11 ms 3284 KB Output is correct
5 Correct 15 ms 4304 KB Output is correct
6 Correct 11 ms 3408 KB Output is correct
7 Correct 3 ms 1248 KB Output is correct
8 Correct 10 ms 3288 KB Output is correct
9 Correct 24 ms 6600 KB Output is correct
10 Correct 16 ms 3772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 472 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 464 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 472 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 464 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 6 ms 2012 KB Output is correct
17 Correct 19 ms 6996 KB Output is correct
18 Correct 22 ms 7656 KB Output is correct
19 Correct 24 ms 6868 KB Output is correct
20 Correct 27 ms 7580 KB Output is correct
21 Correct 18 ms 7636 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 10 ms 3288 KB Output is correct
24 Correct 20 ms 6356 KB Output is correct
25 Correct 2 ms 1248 KB Output is correct
26 Correct 13 ms 3288 KB Output is correct
27 Correct 16 ms 6868 KB Output is correct
28 Correct 21 ms 7380 KB Output is correct
29 Correct 8 ms 3032 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 4816 KB Output is correct
2 Correct 5 ms 1756 KB Output is correct
3 Correct 12 ms 3944 KB Output is correct
4 Correct 11 ms 3284 KB Output is correct
5 Correct 15 ms 4304 KB Output is correct
6 Correct 11 ms 3408 KB Output is correct
7 Correct 3 ms 1248 KB Output is correct
8 Correct 10 ms 3288 KB Output is correct
9 Correct 24 ms 6600 KB Output is correct
10 Correct 16 ms 3772 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 472 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 464 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 6 ms 2012 KB Output is correct
27 Correct 19 ms 6996 KB Output is correct
28 Correct 22 ms 7656 KB Output is correct
29 Correct 24 ms 6868 KB Output is correct
30 Correct 27 ms 7580 KB Output is correct
31 Correct 18 ms 7636 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 10 ms 3288 KB Output is correct
34 Correct 20 ms 6356 KB Output is correct
35 Correct 2 ms 1248 KB Output is correct
36 Correct 13 ms 3288 KB Output is correct
37 Correct 16 ms 6868 KB Output is correct
38 Correct 21 ms 7380 KB Output is correct
39 Correct 8 ms 3032 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 45 ms 8116 KB Output is correct
42 Correct 28 ms 7152 KB Output is correct
43 Correct 35 ms 6584 KB Output is correct
44 Correct 36 ms 7116 KB Output is correct
45 Correct 27 ms 7656 KB Output is correct
46 Correct 47 ms 7124 KB Output is correct
47 Correct 24 ms 8404 KB Output is correct
48 Correct 30 ms 7124 KB Output is correct
49 Correct 31 ms 7120 KB Output is correct
50 Correct 137 ms 7888 KB Output is correct
51 Correct 140 ms 7108 KB Output is correct
52 Correct 138 ms 7368 KB Output is correct
53 Correct 145 ms 7112 KB Output is correct
54 Correct 134 ms 6564 KB Output is correct
55 Correct 139 ms 8148 KB Output is correct
56 Correct 129 ms 7372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 460 KB Output is correct
9 Correct 17 ms 4816 KB Output is correct
10 Correct 5 ms 1756 KB Output is correct
11 Correct 12 ms 3944 KB Output is correct
12 Correct 11 ms 3284 KB Output is correct
13 Correct 15 ms 4304 KB Output is correct
14 Correct 11 ms 3408 KB Output is correct
15 Correct 3 ms 1248 KB Output is correct
16 Correct 10 ms 3288 KB Output is correct
17 Correct 24 ms 6600 KB Output is correct
18 Correct 16 ms 3772 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 472 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 464 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 6 ms 2012 KB Output is correct
35 Correct 19 ms 6996 KB Output is correct
36 Correct 22 ms 7656 KB Output is correct
37 Correct 24 ms 6868 KB Output is correct
38 Correct 27 ms 7580 KB Output is correct
39 Correct 18 ms 7636 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 10 ms 3288 KB Output is correct
42 Correct 20 ms 6356 KB Output is correct
43 Correct 2 ms 1248 KB Output is correct
44 Correct 13 ms 3288 KB Output is correct
45 Correct 16 ms 6868 KB Output is correct
46 Correct 21 ms 7380 KB Output is correct
47 Correct 8 ms 3032 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 45 ms 8116 KB Output is correct
50 Correct 28 ms 7152 KB Output is correct
51 Correct 35 ms 6584 KB Output is correct
52 Correct 36 ms 7116 KB Output is correct
53 Correct 27 ms 7656 KB Output is correct
54 Correct 47 ms 7124 KB Output is correct
55 Correct 24 ms 8404 KB Output is correct
56 Correct 30 ms 7124 KB Output is correct
57 Correct 31 ms 7120 KB Output is correct
58 Correct 137 ms 7888 KB Output is correct
59 Correct 140 ms 7108 KB Output is correct
60 Correct 138 ms 7368 KB Output is correct
61 Correct 145 ms 7112 KB Output is correct
62 Correct 134 ms 6564 KB Output is correct
63 Correct 139 ms 8148 KB Output is correct
64 Correct 129 ms 7372 KB Output is correct
65 Correct 1 ms 456 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 139 ms 6868 KB Output is correct
68 Correct 136 ms 7884 KB Output is correct
69 Correct 131 ms 6612 KB Output is correct
70 Correct 129 ms 7636 KB Output is correct
71 Correct 136 ms 7880 KB Output is correct
72 Correct 128 ms 7880 KB Output is correct
73 Correct 128 ms 7112 KB Output is correct
74 Correct 144 ms 6956 KB Output is correct
75 Correct 133 ms 8144 KB Output is correct
76 Correct 134 ms 7880 KB Output is correct
77 Correct 40 ms 7376 KB Output is correct
78 Correct 27 ms 7372 KB Output is correct
79 Correct 35 ms 7880 KB Output is correct
80 Correct 34 ms 7380 KB Output is correct
81 Correct 35 ms 7124 KB Output is correct
82 Correct 32 ms 7120 KB Output is correct
83 Correct 27 ms 8148 KB Output is correct
84 Correct 93 ms 7412 KB Output is correct
85 Correct 144 ms 7636 KB Output is correct
86 Correct 57 ms 1736 KB Output is correct
87 Correct 57 ms 1628 KB Output is correct
88 Correct 137 ms 7364 KB Output is correct
89 Correct 73 ms 2776 KB Output is correct
90 Correct 57 ms 1624 KB Output is correct