답안 #879129

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
879129 2023-11-26T12:06:59 Z TahirAliyev Chessboard (IZhO18_chessboard) C++17
100 / 100
194 ms 6628 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define oo 1e12
#define int ll


int n, k;
const int MAX = 1e5 + 5;
vector<array<int, 4>> black;

vector<int> s;

signed main(){
    cin >> n >> k;
    for(int i = 1; i <= k; i++){
        int a, b, c, d; cin >> a >> b >> c >> d;
        black.push_back({a, b, c, d});
    }
    s.push_back(1);
    for(int d = 2; d * d <= n; d++){
        if(n % d == 0){
            s.push_back(d);
            if(n / d != d){
                s.push_back(n / d);
            }
        }
    }
    int ans = oo;
    for(int a : s){
        int pre[n + 1];
        pre[0] = 0;
        for(int i = 1; i <= n; i++){
            pre[i] = pre[i - 1] + (((i - 1) / a + 1) % 2);
        }
        int tmp = ((n / a) * (n / a) + 1) / 2 * a * a;
        for(auto b : black){
            int p1 = pre[b[2]] - pre[b[0] - 1];
            int p2 = pre[b[3]] - pre[b[1] - 1];
            int x = (b[2] - b[0] + 1);
            int y = (b[3] - b[1] + 1);
            tmp -= x * y - 2 * (p1 * (y - p2) + p2 * (x - p1));
        }
        ans = min(tmp, ans);    
        ans = min(n * n - tmp, ans);
    }
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 352 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 344 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 2904 KB Output is correct
2 Correct 13 ms 1492 KB Output is correct
3 Correct 36 ms 2364 KB Output is correct
4 Correct 32 ms 2488 KB Output is correct
5 Correct 47 ms 2504 KB Output is correct
6 Correct 30 ms 2496 KB Output is correct
7 Correct 6 ms 756 KB Output is correct
8 Correct 32 ms 2592 KB Output is correct
9 Correct 91 ms 5056 KB Output is correct
10 Correct 40 ms 2512 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 1 ms 348 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 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 1 ms 344 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 1 ms 348 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 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 17 ms 1488 KB Output is correct
17 Correct 72 ms 5312 KB Output is correct
18 Correct 71 ms 5704 KB Output is correct
19 Correct 64 ms 6628 KB Output is correct
20 Correct 66 ms 5616 KB Output is correct
21 Correct 50 ms 5920 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 27 ms 2508 KB Output is correct
24 Correct 55 ms 5820 KB Output is correct
25 Correct 6 ms 1236 KB Output is correct
26 Correct 50 ms 2504 KB Output is correct
27 Correct 53 ms 5824 KB Output is correct
28 Correct 61 ms 5596 KB Output is correct
29 Correct 21 ms 2512 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 2904 KB Output is correct
2 Correct 13 ms 1492 KB Output is correct
3 Correct 36 ms 2364 KB Output is correct
4 Correct 32 ms 2488 KB Output is correct
5 Correct 47 ms 2504 KB Output is correct
6 Correct 30 ms 2496 KB Output is correct
7 Correct 6 ms 756 KB Output is correct
8 Correct 32 ms 2592 KB Output is correct
9 Correct 91 ms 5056 KB Output is correct
10 Correct 40 ms 2512 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 348 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 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 17 ms 1488 KB Output is correct
27 Correct 72 ms 5312 KB Output is correct
28 Correct 71 ms 5704 KB Output is correct
29 Correct 64 ms 6628 KB Output is correct
30 Correct 66 ms 5616 KB Output is correct
31 Correct 50 ms 5920 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 27 ms 2508 KB Output is correct
34 Correct 55 ms 5820 KB Output is correct
35 Correct 6 ms 1236 KB Output is correct
36 Correct 50 ms 2504 KB Output is correct
37 Correct 53 ms 5824 KB Output is correct
38 Correct 61 ms 5596 KB Output is correct
39 Correct 21 ms 2512 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 88 ms 6044 KB Output is correct
42 Correct 103 ms 6308 KB Output is correct
43 Correct 116 ms 5300 KB Output is correct
44 Correct 74 ms 5072 KB Output is correct
45 Correct 78 ms 4544 KB Output is correct
46 Correct 94 ms 5688 KB Output is correct
47 Correct 103 ms 5056 KB Output is correct
48 Correct 75 ms 6080 KB Output is correct
49 Correct 81 ms 6556 KB Output is correct
50 Correct 167 ms 5060 KB Output is correct
51 Correct 194 ms 6080 KB Output is correct
52 Correct 186 ms 5268 KB Output is correct
53 Correct 179 ms 4920 KB Output is correct
54 Correct 183 ms 6004 KB Output is correct
55 Correct 194 ms 5904 KB Output is correct
56 Correct 175 ms 4800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 352 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 344 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 57 ms 2904 KB Output is correct
10 Correct 13 ms 1492 KB Output is correct
11 Correct 36 ms 2364 KB Output is correct
12 Correct 32 ms 2488 KB Output is correct
13 Correct 47 ms 2504 KB Output is correct
14 Correct 30 ms 2496 KB Output is correct
15 Correct 6 ms 756 KB Output is correct
16 Correct 32 ms 2592 KB Output is correct
17 Correct 91 ms 5056 KB Output is correct
18 Correct 40 ms 2512 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 348 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 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 17 ms 1488 KB Output is correct
35 Correct 72 ms 5312 KB Output is correct
36 Correct 71 ms 5704 KB Output is correct
37 Correct 64 ms 6628 KB Output is correct
38 Correct 66 ms 5616 KB Output is correct
39 Correct 50 ms 5920 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 27 ms 2508 KB Output is correct
42 Correct 55 ms 5820 KB Output is correct
43 Correct 6 ms 1236 KB Output is correct
44 Correct 50 ms 2504 KB Output is correct
45 Correct 53 ms 5824 KB Output is correct
46 Correct 61 ms 5596 KB Output is correct
47 Correct 21 ms 2512 KB Output is correct
48 Correct 2 ms 604 KB Output is correct
49 Correct 88 ms 6044 KB Output is correct
50 Correct 103 ms 6308 KB Output is correct
51 Correct 116 ms 5300 KB Output is correct
52 Correct 74 ms 5072 KB Output is correct
53 Correct 78 ms 4544 KB Output is correct
54 Correct 94 ms 5688 KB Output is correct
55 Correct 103 ms 5056 KB Output is correct
56 Correct 75 ms 6080 KB Output is correct
57 Correct 81 ms 6556 KB Output is correct
58 Correct 167 ms 5060 KB Output is correct
59 Correct 194 ms 6080 KB Output is correct
60 Correct 186 ms 5268 KB Output is correct
61 Correct 179 ms 4920 KB Output is correct
62 Correct 183 ms 6004 KB Output is correct
63 Correct 194 ms 5904 KB Output is correct
64 Correct 175 ms 4800 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 189 ms 5652 KB Output is correct
68 Correct 174 ms 6184 KB Output is correct
69 Correct 165 ms 6360 KB Output is correct
70 Correct 180 ms 4696 KB Output is correct
71 Correct 163 ms 5300 KB Output is correct
72 Correct 161 ms 4920 KB Output is correct
73 Correct 175 ms 5228 KB Output is correct
74 Correct 176 ms 5056 KB Output is correct
75 Correct 160 ms 5284 KB Output is correct
76 Correct 174 ms 4760 KB Output is correct
77 Correct 138 ms 6196 KB Output is correct
78 Correct 72 ms 4796 KB Output is correct
79 Correct 78 ms 6332 KB Output is correct
80 Correct 80 ms 5312 KB Output is correct
81 Correct 74 ms 5644 KB Output is correct
82 Correct 80 ms 5448 KB Output is correct
83 Correct 74 ms 6184 KB Output is correct
84 Correct 145 ms 5312 KB Output is correct
85 Correct 186 ms 6076 KB Output is correct
86 Correct 57 ms 860 KB Output is correct
87 Correct 57 ms 860 KB Output is correct
88 Correct 176 ms 5856 KB Output is correct
89 Correct 79 ms 1740 KB Output is correct
90 Correct 57 ms 856 KB Output is correct