Submission #946060

# Submission time Handle Problem Language Result Execution time Memory
946060 2024-03-14T09:54:21 Z atom Chessboard (IZhO18_chessboard) C++17
100 / 100
798 ms 10240 KB
#include "bits/stdc++.h"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;

#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif

#define int long long

vector <vector <int>> rect;
int n, m;
int res = 1e18;

int f(int x, int y, int k) {
    int cnt = 0;
    int _x = (x / k) * k, _y = (y / k) * k;
    if ((_x / k + _y / k) & 1) {
        cnt += ((_x / k) * (_y / k)) / 2 * (k * k);
        cnt += ((_y / k) + 1) / 2 * (x - _x) * k;
        cnt += ((_x / k) + 1) / 2 * (y - _y) * k;
    }
    else {
        cnt += ((_x / k) * (_y / k) + 1) / 2 * (k * k);
        cnt += ((_y / k)) / 2 * (x - _x) * k;
        cnt += ((_x / k)) / 2 * (y - _y) * k;
        cnt += (x - _x) * (y - _y);
    }
    return cnt;
}

void solve(int k) {
    int ans = (n * n - f(n, n, k));
    for (auto x : rect) {
        int x1 = x[0], y1 = x[1], x2 = x[2], y2 = x[3];
        int w = f(x2, y2, k) + f(x1 - 1, y1 - 1, k) - f(x2, y1 - 1, k) - f(x1 - 1, y2, k);
        ans += w;
        ans -= (x2 - x1 + 1) * (y2 - y1 + 1) - w; 
    }

    res = min({res, ans, n * n - ans});
}

signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    
    #ifdef JASPER
        freopen("in1", "r", stdin);
    #endif
        
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        rect.push_back({x1, y1, x2, y2});
    }

    for (int i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            solve(i);
            if (i != n / i && i > 1)
                solve(n / i); 
        }
    }
    cout << res << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 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 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 6672 KB Output is correct
2 Correct 6 ms 2200 KB Output is correct
3 Correct 15 ms 4372 KB Output is correct
4 Correct 18 ms 4368 KB Output is correct
5 Correct 20 ms 5392 KB Output is correct
6 Correct 16 ms 4372 KB Output is correct
7 Correct 3 ms 1116 KB Output is correct
8 Correct 12 ms 4372 KB Output is correct
9 Correct 32 ms 9468 KB Output is correct
10 Correct 18 ms 5136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 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 0 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 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 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 0 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 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 13 ms 2864 KB Output is correct
17 Correct 29 ms 8264 KB Output is correct
18 Correct 39 ms 9488 KB Output is correct
19 Correct 145 ms 8720 KB Output is correct
20 Correct 160 ms 9588 KB Output is correct
21 Correct 27 ms 8976 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 28 ms 4116 KB Output is correct
24 Correct 36 ms 9232 KB Output is correct
25 Correct 5 ms 1368 KB Output is correct
26 Correct 24 ms 5176 KB Output is correct
27 Correct 35 ms 8720 KB Output is correct
28 Correct 39 ms 8976 KB Output is correct
29 Correct 13 ms 3860 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 6672 KB Output is correct
2 Correct 6 ms 2200 KB Output is correct
3 Correct 15 ms 4372 KB Output is correct
4 Correct 18 ms 4368 KB Output is correct
5 Correct 20 ms 5392 KB Output is correct
6 Correct 16 ms 4372 KB Output is correct
7 Correct 3 ms 1116 KB Output is correct
8 Correct 12 ms 4372 KB Output is correct
9 Correct 32 ms 9468 KB Output is correct
10 Correct 18 ms 5136 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 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 0 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 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 13 ms 2864 KB Output is correct
27 Correct 29 ms 8264 KB Output is correct
28 Correct 39 ms 9488 KB Output is correct
29 Correct 145 ms 8720 KB Output is correct
30 Correct 160 ms 9588 KB Output is correct
31 Correct 27 ms 8976 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 28 ms 4116 KB Output is correct
34 Correct 36 ms 9232 KB Output is correct
35 Correct 5 ms 1368 KB Output is correct
36 Correct 24 ms 5176 KB Output is correct
37 Correct 35 ms 8720 KB Output is correct
38 Correct 39 ms 8976 KB Output is correct
39 Correct 13 ms 3860 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 126 ms 9232 KB Output is correct
42 Correct 43 ms 9984 KB Output is correct
43 Correct 79 ms 8368 KB Output is correct
44 Correct 41 ms 9732 KB Output is correct
45 Correct 42 ms 9648 KB Output is correct
46 Correct 167 ms 8968 KB Output is correct
47 Correct 31 ms 8460 KB Output is correct
48 Correct 65 ms 8452 KB Output is correct
49 Correct 38 ms 8712 KB Output is correct
50 Correct 667 ms 8944 KB Output is correct
51 Correct 715 ms 9412 KB Output is correct
52 Correct 655 ms 8724 KB Output is correct
53 Correct 679 ms 9456 KB Output is correct
54 Correct 638 ms 8580 KB Output is correct
55 Correct 798 ms 9980 KB Output is correct
56 Correct 676 ms 8572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 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 344 KB Output is correct
9 Correct 29 ms 6672 KB Output is correct
10 Correct 6 ms 2200 KB Output is correct
11 Correct 15 ms 4372 KB Output is correct
12 Correct 18 ms 4368 KB Output is correct
13 Correct 20 ms 5392 KB Output is correct
14 Correct 16 ms 4372 KB Output is correct
15 Correct 3 ms 1116 KB Output is correct
16 Correct 12 ms 4372 KB Output is correct
17 Correct 32 ms 9468 KB Output is correct
18 Correct 18 ms 5136 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 344 KB Output is correct
22 Correct 1 ms 344 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 1 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 1 ms 348 KB Output is correct
30 Correct 1 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 13 ms 2864 KB Output is correct
35 Correct 29 ms 8264 KB Output is correct
36 Correct 39 ms 9488 KB Output is correct
37 Correct 145 ms 8720 KB Output is correct
38 Correct 160 ms 9588 KB Output is correct
39 Correct 27 ms 8976 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 28 ms 4116 KB Output is correct
42 Correct 36 ms 9232 KB Output is correct
43 Correct 5 ms 1368 KB Output is correct
44 Correct 24 ms 5176 KB Output is correct
45 Correct 35 ms 8720 KB Output is correct
46 Correct 39 ms 8976 KB Output is correct
47 Correct 13 ms 3860 KB Output is correct
48 Correct 2 ms 604 KB Output is correct
49 Correct 126 ms 9232 KB Output is correct
50 Correct 43 ms 9984 KB Output is correct
51 Correct 79 ms 8368 KB Output is correct
52 Correct 41 ms 9732 KB Output is correct
53 Correct 42 ms 9648 KB Output is correct
54 Correct 167 ms 8968 KB Output is correct
55 Correct 31 ms 8460 KB Output is correct
56 Correct 65 ms 8452 KB Output is correct
57 Correct 38 ms 8712 KB Output is correct
58 Correct 667 ms 8944 KB Output is correct
59 Correct 715 ms 9412 KB Output is correct
60 Correct 655 ms 8724 KB Output is correct
61 Correct 679 ms 9456 KB Output is correct
62 Correct 638 ms 8580 KB Output is correct
63 Correct 798 ms 9980 KB Output is correct
64 Correct 676 ms 8572 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 0 ms 460 KB Output is correct
67 Correct 748 ms 9596 KB Output is correct
68 Correct 738 ms 9060 KB Output is correct
69 Correct 632 ms 8208 KB Output is correct
70 Correct 646 ms 9488 KB Output is correct
71 Correct 698 ms 8748 KB Output is correct
72 Correct 695 ms 8968 KB Output is correct
73 Correct 675 ms 9384 KB Output is correct
74 Correct 744 ms 9732 KB Output is correct
75 Correct 708 ms 8708 KB Output is correct
76 Correct 714 ms 9920 KB Output is correct
77 Correct 132 ms 10236 KB Output is correct
78 Correct 44 ms 9244 KB Output is correct
79 Correct 91 ms 8368 KB Output is correct
80 Correct 84 ms 9488 KB Output is correct
81 Correct 106 ms 9564 KB Output is correct
82 Correct 71 ms 9216 KB Output is correct
83 Correct 55 ms 8460 KB Output is correct
84 Correct 448 ms 10240 KB Output is correct
85 Correct 769 ms 10068 KB Output is correct
86 Correct 1 ms 348 KB Output is correct
87 Correct 0 ms 348 KB Output is correct
88 Correct 721 ms 9704 KB Output is correct
89 Correct 150 ms 2456 KB Output is correct
90 Correct 1 ms 348 KB Output is correct