Submission #898279

# Submission time Handle Problem Language Result Execution time Memory
898279 2024-01-04T12:30:41 Z marcid Chessboard (IZhO18_chessboard) C++17
100 / 100
153 ms 8404 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
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 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 456 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 4468 KB Output is correct
2 Correct 5 ms 1756 KB Output is correct
3 Correct 12 ms 3900 KB Output is correct
4 Correct 11 ms 3288 KB Output is correct
5 Correct 15 ms 4052 KB Output is correct
6 Correct 14 ms 3308 KB Output is correct
7 Correct 3 ms 1180 KB Output is correct
8 Correct 11 ms 3320 KB Output is correct
9 Correct 24 ms 6612 KB Output is correct
10 Correct 19 ms 3488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 452 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 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 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 452 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 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 344 KB Output is correct
16 Correct 6 ms 2012 KB Output is correct
17 Correct 23 ms 7668 KB Output is correct
18 Correct 29 ms 6092 KB Output is correct
19 Correct 24 ms 6864 KB Output is correct
20 Correct 27 ms 6612 KB Output is correct
21 Correct 18 ms 6216 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 10 ms 3288 KB Output is correct
24 Correct 20 ms 6428 KB Output is correct
25 Correct 3 ms 1248 KB Output is correct
26 Correct 13 ms 3332 KB Output is correct
27 Correct 16 ms 7632 KB Output is correct
28 Correct 21 ms 7124 KB Output is correct
29 Correct 8 ms 3028 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 4468 KB Output is correct
2 Correct 5 ms 1756 KB Output is correct
3 Correct 12 ms 3900 KB Output is correct
4 Correct 11 ms 3288 KB Output is correct
5 Correct 15 ms 4052 KB Output is correct
6 Correct 14 ms 3308 KB Output is correct
7 Correct 3 ms 1180 KB Output is correct
8 Correct 11 ms 3320 KB Output is correct
9 Correct 24 ms 6612 KB Output is correct
10 Correct 19 ms 3488 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 452 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 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 0 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 344 KB Output is correct
26 Correct 6 ms 2012 KB Output is correct
27 Correct 23 ms 7668 KB Output is correct
28 Correct 29 ms 6092 KB Output is correct
29 Correct 24 ms 6864 KB Output is correct
30 Correct 27 ms 6612 KB Output is correct
31 Correct 18 ms 6216 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 10 ms 3288 KB Output is correct
34 Correct 20 ms 6428 KB Output is correct
35 Correct 3 ms 1248 KB Output is correct
36 Correct 13 ms 3332 KB Output is correct
37 Correct 16 ms 7632 KB Output is correct
38 Correct 21 ms 7124 KB Output is correct
39 Correct 8 ms 3028 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 46 ms 7380 KB Output is correct
42 Correct 28 ms 7112 KB Output is correct
43 Correct 34 ms 7648 KB Output is correct
44 Correct 27 ms 7116 KB Output is correct
45 Correct 26 ms 7356 KB Output is correct
46 Correct 48 ms 8076 KB Output is correct
47 Correct 24 ms 7380 KB Output is correct
48 Correct 38 ms 7220 KB Output is correct
49 Correct 32 ms 8404 KB Output is correct
50 Correct 136 ms 6792 KB Output is correct
51 Correct 141 ms 7112 KB Output is correct
52 Correct 136 ms 7892 KB Output is correct
53 Correct 139 ms 7380 KB Output is correct
54 Correct 133 ms 7892 KB Output is correct
55 Correct 153 ms 7224 KB Output is correct
56 Correct 132 ms 7176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 456 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 18 ms 4468 KB Output is correct
10 Correct 5 ms 1756 KB Output is correct
11 Correct 12 ms 3900 KB Output is correct
12 Correct 11 ms 3288 KB Output is correct
13 Correct 15 ms 4052 KB Output is correct
14 Correct 14 ms 3308 KB Output is correct
15 Correct 3 ms 1180 KB Output is correct
16 Correct 11 ms 3320 KB Output is correct
17 Correct 24 ms 6612 KB Output is correct
18 Correct 19 ms 3488 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 452 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 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 344 KB Output is correct
34 Correct 6 ms 2012 KB Output is correct
35 Correct 23 ms 7668 KB Output is correct
36 Correct 29 ms 6092 KB Output is correct
37 Correct 24 ms 6864 KB Output is correct
38 Correct 27 ms 6612 KB Output is correct
39 Correct 18 ms 6216 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 10 ms 3288 KB Output is correct
42 Correct 20 ms 6428 KB Output is correct
43 Correct 3 ms 1248 KB Output is correct
44 Correct 13 ms 3332 KB Output is correct
45 Correct 16 ms 7632 KB Output is correct
46 Correct 21 ms 7124 KB Output is correct
47 Correct 8 ms 3028 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 46 ms 7380 KB Output is correct
50 Correct 28 ms 7112 KB Output is correct
51 Correct 34 ms 7648 KB Output is correct
52 Correct 27 ms 7116 KB Output is correct
53 Correct 26 ms 7356 KB Output is correct
54 Correct 48 ms 8076 KB Output is correct
55 Correct 24 ms 7380 KB Output is correct
56 Correct 38 ms 7220 KB Output is correct
57 Correct 32 ms 8404 KB Output is correct
58 Correct 136 ms 6792 KB Output is correct
59 Correct 141 ms 7112 KB Output is correct
60 Correct 136 ms 7892 KB Output is correct
61 Correct 139 ms 7380 KB Output is correct
62 Correct 133 ms 7892 KB Output is correct
63 Correct 153 ms 7224 KB Output is correct
64 Correct 132 ms 7176 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 145 ms 8272 KB Output is correct
68 Correct 149 ms 7124 KB Output is correct
69 Correct 125 ms 7636 KB Output is correct
70 Correct 131 ms 7124 KB Output is correct
71 Correct 130 ms 6604 KB Output is correct
72 Correct 134 ms 6724 KB Output is correct
73 Correct 143 ms 7112 KB Output is correct
74 Correct 138 ms 6860 KB Output is correct
75 Correct 129 ms 7880 KB Output is correct
76 Correct 132 ms 6856 KB Output is correct
77 Correct 40 ms 7624 KB Output is correct
78 Correct 29 ms 7044 KB Output is correct
79 Correct 33 ms 7620 KB Output is correct
80 Correct 34 ms 8024 KB Output is correct
81 Correct 33 ms 7504 KB Output is correct
82 Correct 31 ms 7208 KB Output is correct
83 Correct 28 ms 6856 KB Output is correct
84 Correct 110 ms 7632 KB Output is correct
85 Correct 148 ms 8148 KB Output is correct
86 Correct 57 ms 1628 KB Output is correct
87 Correct 58 ms 1628 KB Output is correct
88 Correct 152 ms 7468 KB Output is correct
89 Correct 73 ms 2772 KB Output is correct
90 Correct 57 ms 1624 KB Output is correct