Submission #906019

# Submission time Handle Problem Language Result Execution time Memory
906019 2024-01-13T09:50:46 Z rockstar Chessboard (IZhO18_chessboard) C++17
100 / 100
404 ms 5724 KB
//#pragma GCC optimize("O3,unroll-loops,inline,fast-math")
//#pragma GCC target("avx,avx2,sse3,ssse3,sse4.1,sse4.2,fma,bmi2,abm,popcnt,mmx,tune=native")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

#define int ll
#define all(a) a.begin(), a.end()

void solve() {
    int n, k;
    cin >> n >> k;
    vector<array<int, 4>> p(k);
    for (auto &i : p)
        cin >> i[0] >> i[1] >> i[2] >> i[3];
    int res = 1e18;
    auto pref = [](int i, int j, int l) {
        int ii = i / l * l, jj = j / l * l;
        int res = 0;
        if ((ii / l + jj / l) % 2) {
            res += (ii / l) * (jj / l) / 2 * l * l;
            res += ((jj / l) + 1) / 2 * l * (i - ii);
            res += ((ii / l) + 1) / 2 * l * (j - jj);
        } else {
            res += (i - ii) * (j - jj);
            res += ((ii / l) * (jj / l) + 1) / 2 * l * l;
            res += (jj / l) / 2 * l * (i - ii);
            res += (ii / l) / 2 * l * (j - jj);
        }
        return res;
    };
    auto upd = [&](int l) {
        int now = n * n - pref(n, n, l);
        for (auto i : p) {
            int w = pref(i[2], i[3], l) + pref(i[0] - 1, i[1] - 1, l) - pref(i[2], i[1] - 1, l) - pref(i[0] - 1, i[3], l);
            now += w;
            now -= (i[2] - i[0] + 1) * (i[3] - i[1] + 1) - w;
        }
        res = min(res, min(now, n * n - now));
    };
    for (int i = 1; i * i <= n; ++i)
        if (n % i == 0) {
            upd(i);
            if (n / i != i && i != 1)
                upd(n / i);
        }
    cout << res;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
//    cin >> t;
    while (t--)
        solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 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 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
# Verdict Execution time Memory Grader output
1 Correct 17 ms 3928 KB Output is correct
2 Correct 5 ms 1116 KB Output is correct
3 Correct 11 ms 2396 KB Output is correct
4 Correct 13 ms 2652 KB Output is correct
5 Correct 15 ms 3436 KB Output is correct
6 Correct 10 ms 2312 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 11 ms 2140 KB Output is correct
9 Correct 25 ms 5204 KB Output is correct
10 Correct 15 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 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 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 1 ms 348 KB Output is correct
10 Correct 1 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 1 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 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 1 ms 348 KB Output is correct
10 Correct 1 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 9 ms 1628 KB Output is correct
17 Correct 20 ms 4444 KB Output is correct
18 Correct 29 ms 4956 KB Output is correct
19 Correct 85 ms 4444 KB Output is correct
20 Correct 94 ms 4956 KB Output is correct
21 Correct 19 ms 4188 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 18 ms 2396 KB Output is correct
24 Correct 27 ms 4664 KB Output is correct
25 Correct 4 ms 860 KB Output is correct
26 Correct 17 ms 2908 KB Output is correct
27 Correct 24 ms 3676 KB Output is correct
28 Correct 27 ms 4956 KB Output is correct
29 Correct 9 ms 1884 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 3928 KB Output is correct
2 Correct 5 ms 1116 KB Output is correct
3 Correct 11 ms 2396 KB Output is correct
4 Correct 13 ms 2652 KB Output is correct
5 Correct 15 ms 3436 KB Output is correct
6 Correct 10 ms 2312 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 11 ms 2140 KB Output is correct
9 Correct 25 ms 5204 KB Output is correct
10 Correct 15 ms 3164 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 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 1 ms 348 KB Output is correct
20 Correct 1 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 9 ms 1628 KB Output is correct
27 Correct 20 ms 4444 KB Output is correct
28 Correct 29 ms 4956 KB Output is correct
29 Correct 85 ms 4444 KB Output is correct
30 Correct 94 ms 4956 KB Output is correct
31 Correct 19 ms 4188 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 18 ms 2396 KB Output is correct
34 Correct 27 ms 4664 KB Output is correct
35 Correct 4 ms 860 KB Output is correct
36 Correct 17 ms 2908 KB Output is correct
37 Correct 24 ms 3676 KB Output is correct
38 Correct 27 ms 4956 KB Output is correct
39 Correct 9 ms 1884 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 76 ms 4956 KB Output is correct
42 Correct 31 ms 5468 KB Output is correct
43 Correct 47 ms 4956 KB Output is correct
44 Correct 31 ms 5460 KB Output is correct
45 Correct 29 ms 5716 KB Output is correct
46 Correct 85 ms 5460 KB Output is correct
47 Correct 23 ms 5180 KB Output is correct
48 Correct 39 ms 5200 KB Output is correct
49 Correct 28 ms 4956 KB Output is correct
50 Correct 344 ms 5340 KB Output is correct
51 Correct 371 ms 5716 KB Output is correct
52 Correct 343 ms 5212 KB Output is correct
53 Correct 377 ms 5632 KB Output is correct
54 Correct 341 ms 5212 KB Output is correct
55 Correct 385 ms 5716 KB Output is correct
56 Correct 328 ms 5204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 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 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 17 ms 3928 KB Output is correct
10 Correct 5 ms 1116 KB Output is correct
11 Correct 11 ms 2396 KB Output is correct
12 Correct 13 ms 2652 KB Output is correct
13 Correct 15 ms 3436 KB Output is correct
14 Correct 10 ms 2312 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 11 ms 2140 KB Output is correct
17 Correct 25 ms 5204 KB Output is correct
18 Correct 15 ms 3164 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 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 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 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 9 ms 1628 KB Output is correct
35 Correct 20 ms 4444 KB Output is correct
36 Correct 29 ms 4956 KB Output is correct
37 Correct 85 ms 4444 KB Output is correct
38 Correct 94 ms 4956 KB Output is correct
39 Correct 19 ms 4188 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 18 ms 2396 KB Output is correct
42 Correct 27 ms 4664 KB Output is correct
43 Correct 4 ms 860 KB Output is correct
44 Correct 17 ms 2908 KB Output is correct
45 Correct 24 ms 3676 KB Output is correct
46 Correct 27 ms 4956 KB Output is correct
47 Correct 9 ms 1884 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 76 ms 4956 KB Output is correct
50 Correct 31 ms 5468 KB Output is correct
51 Correct 47 ms 4956 KB Output is correct
52 Correct 31 ms 5460 KB Output is correct
53 Correct 29 ms 5716 KB Output is correct
54 Correct 85 ms 5460 KB Output is correct
55 Correct 23 ms 5180 KB Output is correct
56 Correct 39 ms 5200 KB Output is correct
57 Correct 28 ms 4956 KB Output is correct
58 Correct 344 ms 5340 KB Output is correct
59 Correct 371 ms 5716 KB Output is correct
60 Correct 343 ms 5212 KB Output is correct
61 Correct 377 ms 5632 KB Output is correct
62 Correct 341 ms 5212 KB Output is correct
63 Correct 385 ms 5716 KB Output is correct
64 Correct 328 ms 5204 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 377 ms 5460 KB Output is correct
68 Correct 404 ms 5460 KB Output is correct
69 Correct 332 ms 4700 KB Output is correct
70 Correct 368 ms 5408 KB Output is correct
71 Correct 357 ms 5212 KB Output is correct
72 Correct 358 ms 5464 KB Output is correct
73 Correct 350 ms 4956 KB Output is correct
74 Correct 376 ms 5720 KB Output is correct
75 Correct 366 ms 5464 KB Output is correct
76 Correct 382 ms 5468 KB Output is correct
77 Correct 69 ms 5724 KB Output is correct
78 Correct 31 ms 5212 KB Output is correct
79 Correct 50 ms 4948 KB Output is correct
80 Correct 54 ms 5272 KB Output is correct
81 Correct 49 ms 4956 KB Output is correct
82 Correct 44 ms 5468 KB Output is correct
83 Correct 36 ms 5204 KB Output is correct
84 Correct 235 ms 5636 KB Output is correct
85 Correct 398 ms 5716 KB Output is correct
86 Correct 1 ms 348 KB Output is correct
87 Correct 1 ms 348 KB Output is correct
88 Correct 401 ms 5716 KB Output is correct
89 Correct 77 ms 1372 KB Output is correct
90 Correct 1 ms 348 KB Output is correct