답안 #898335

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
898335 2024-01-04T14:02:07 Z marcid Chessboard (IZhO18_chessboard) C++17
100 / 100
158 ms 7992 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;
}
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 3276 KB Output is correct
2 Correct 5 ms 1876 KB Output is correct
3 Correct 12 ms 3796 KB Output is correct
4 Correct 12 ms 2992 KB Output is correct
5 Correct 18 ms 4204 KB Output is correct
6 Correct 11 ms 3028 KB Output is correct
7 Correct 3 ms 1116 KB Output is correct
8 Correct 13 ms 3024 KB Output is correct
9 Correct 27 ms 6796 KB Output is correct
10 Correct 17 ms 3480 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 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 460 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 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 460 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 7 ms 2012 KB Output is correct
17 Correct 20 ms 6092 KB Output is correct
18 Correct 22 ms 6868 KB Output is correct
19 Correct 24 ms 6348 KB Output is correct
20 Correct 27 ms 7488 KB Output is correct
21 Correct 18 ms 6356 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 11 ms 3032 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 3284 KB Output is correct
27 Correct 22 ms 6868 KB Output is correct
28 Correct 22 ms 6076 KB Output is correct
29 Correct 8 ms 3032 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 3276 KB Output is correct
2 Correct 5 ms 1876 KB Output is correct
3 Correct 12 ms 3796 KB Output is correct
4 Correct 12 ms 2992 KB Output is correct
5 Correct 18 ms 4204 KB Output is correct
6 Correct 11 ms 3028 KB Output is correct
7 Correct 3 ms 1116 KB Output is correct
8 Correct 13 ms 3024 KB Output is correct
9 Correct 27 ms 6796 KB Output is correct
10 Correct 17 ms 3480 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 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 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 460 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 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 7 ms 2012 KB Output is correct
27 Correct 20 ms 6092 KB Output is correct
28 Correct 22 ms 6868 KB Output is correct
29 Correct 24 ms 6348 KB Output is correct
30 Correct 27 ms 7488 KB Output is correct
31 Correct 18 ms 6356 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 11 ms 3032 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 3284 KB Output is correct
37 Correct 22 ms 6868 KB Output is correct
38 Correct 22 ms 6076 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 7380 KB Output is correct
42 Correct 35 ms 7632 KB Output is correct
43 Correct 39 ms 6352 KB Output is correct
44 Correct 27 ms 7636 KB Output is correct
45 Correct 33 ms 6600 KB Output is correct
46 Correct 53 ms 7404 KB Output is correct
47 Correct 24 ms 7120 KB Output is correct
48 Correct 31 ms 7020 KB Output is correct
49 Correct 25 ms 6356 KB Output is correct
50 Correct 135 ms 6580 KB Output is correct
51 Correct 144 ms 7360 KB Output is correct
52 Correct 139 ms 7992 KB Output is correct
53 Correct 142 ms 7116 KB Output is correct
54 Correct 137 ms 6452 KB Output is correct
55 Correct 150 ms 6352 KB Output is correct
56 Correct 136 ms 7648 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 17 ms 3276 KB Output is correct
10 Correct 5 ms 1876 KB Output is correct
11 Correct 12 ms 3796 KB Output is correct
12 Correct 12 ms 2992 KB Output is correct
13 Correct 18 ms 4204 KB Output is correct
14 Correct 11 ms 3028 KB Output is correct
15 Correct 3 ms 1116 KB Output is correct
16 Correct 13 ms 3024 KB Output is correct
17 Correct 27 ms 6796 KB Output is correct
18 Correct 17 ms 3480 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 0 ms 348 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 460 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 7 ms 2012 KB Output is correct
35 Correct 20 ms 6092 KB Output is correct
36 Correct 22 ms 6868 KB Output is correct
37 Correct 24 ms 6348 KB Output is correct
38 Correct 27 ms 7488 KB Output is correct
39 Correct 18 ms 6356 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 11 ms 3032 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 3284 KB Output is correct
45 Correct 22 ms 6868 KB Output is correct
46 Correct 22 ms 6076 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 7380 KB Output is correct
50 Correct 35 ms 7632 KB Output is correct
51 Correct 39 ms 6352 KB Output is correct
52 Correct 27 ms 7636 KB Output is correct
53 Correct 33 ms 6600 KB Output is correct
54 Correct 53 ms 7404 KB Output is correct
55 Correct 24 ms 7120 KB Output is correct
56 Correct 31 ms 7020 KB Output is correct
57 Correct 25 ms 6356 KB Output is correct
58 Correct 135 ms 6580 KB Output is correct
59 Correct 144 ms 7360 KB Output is correct
60 Correct 139 ms 7992 KB Output is correct
61 Correct 142 ms 7116 KB Output is correct
62 Correct 137 ms 6452 KB Output is correct
63 Correct 150 ms 6352 KB Output is correct
64 Correct 136 ms 7648 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 139 ms 6668 KB Output is correct
68 Correct 145 ms 7888 KB Output is correct
69 Correct 133 ms 7368 KB Output is correct
70 Correct 158 ms 6216 KB Output is correct
71 Correct 147 ms 7744 KB Output is correct
72 Correct 136 ms 5840 KB Output is correct
73 Correct 133 ms 6704 KB Output is correct
74 Correct 149 ms 7500 KB Output is correct
75 Correct 133 ms 7624 KB Output is correct
76 Correct 141 ms 6356 KB Output is correct
77 Correct 41 ms 6836 KB Output is correct
78 Correct 28 ms 7628 KB Output is correct
79 Correct 34 ms 7116 KB Output is correct
80 Correct 36 ms 6604 KB Output is correct
81 Correct 40 ms 6104 KB Output is correct
82 Correct 33 ms 7124 KB Output is correct
83 Correct 29 ms 7124 KB Output is correct
84 Correct 103 ms 7636 KB Output is correct
85 Correct 144 ms 6808 KB Output is correct
86 Correct 57 ms 1624 KB Output is correct
87 Correct 57 ms 1628 KB Output is correct
88 Correct 137 ms 7892 KB Output is correct
89 Correct 75 ms 2772 KB Output is correct
90 Correct 57 ms 1732 KB Output is correct