Submission #523571

# Submission time Handle Problem Language Result Execution time Memory
523571 2022-02-07T19:39:13 Z RaresFelix Chessboard (IZhO18_chessboard) C++17
47 / 100
2000 ms 2508 KB
#include <iostream>
#include <climits>
#include <tuple>
#include <vector>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define MN 107171

using namespace std;
using ll = long long;
ll n, k;
vector<tuple<int, int, int, int>> R;

static inline ll calc(ll a, ll b, ll l) {
    if(a % l == 0 && b % l == 0)
        return ((a / l) * (b / l) + 1) / 2 * l * l;
    if(a % l) {
        ll nrseg;
        if(a / l % 2ll == 0) {
            if(b % (2ll * l) <= l) nrseg = (b / (2ll * l)) * l + b % (2 * l);
            else nrseg = (b / (2ll * l) + 1) * l;
        } else {
            if(b % (2ll * l) <= l) nrseg = (b / (2ll * l)) * l;
            else nrseg = (b / (2ll * l) - 1) * l + b % (2 * l);
        }
        return calc(a - (a % l), b, l) + (a % l) * nrseg;
    }
    return calc(b, a, l);
}
ll sol(ll l) {
    ll arie = ((n / l) * (n / l) + 1) / 2 * l * l, selec;
    for(auto &[a, b, c, d] : R) {
        selec = calc(c, d, l) + calc(a-1, b-1, l) - calc(c, b-1, l) - calc(a-1, d, l);
        arie += (c - a + 1) * (d - b + 1) - 2 * selec;
    }
    return min(arie, 1ll * n * n - arie);
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin >> n >> k;
    for(int i = 1, a, b, c, d; i <= k; ++i)
        cin >> a >> b >> c >> d, R.emplace_back(a, b, c, d);
    ll re = LLONG_MAX;
    for(int i = 1; i < n; ++i)
        if(n % i == 0) re = min(re, sol(i));
    cout << re << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 1484 KB Output is correct
2 Correct 6 ms 904 KB Output is correct
3 Correct 14 ms 1384 KB Output is correct
4 Correct 19 ms 1444 KB Output is correct
5 Correct 20 ms 1380 KB Output is correct
6 Correct 13 ms 1436 KB Output is correct
7 Correct 3 ms 460 KB Output is correct
8 Correct 13 ms 1484 KB Output is correct
9 Correct 31 ms 2508 KB Output is correct
10 Correct 19 ms 1440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 16 ms 976 KB Output is correct
17 Correct 24 ms 2504 KB Output is correct
18 Correct 61 ms 2504 KB Output is correct
19 Correct 392 ms 2504 KB Output is correct
20 Correct 448 ms 2504 KB Output is correct
21 Correct 23 ms 2504 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 51 ms 1484 KB Output is correct
24 Correct 54 ms 2500 KB Output is correct
25 Correct 11 ms 680 KB Output is correct
26 Correct 35 ms 1428 KB Output is correct
27 Correct 60 ms 2504 KB Output is correct
28 Correct 54 ms 2468 KB Output is correct
29 Correct 11 ms 1484 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 1484 KB Output is correct
2 Correct 6 ms 904 KB Output is correct
3 Correct 14 ms 1384 KB Output is correct
4 Correct 19 ms 1444 KB Output is correct
5 Correct 20 ms 1380 KB Output is correct
6 Correct 13 ms 1436 KB Output is correct
7 Correct 3 ms 460 KB Output is correct
8 Correct 13 ms 1484 KB Output is correct
9 Correct 31 ms 2508 KB Output is correct
10 Correct 19 ms 1440 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 16 ms 976 KB Output is correct
27 Correct 24 ms 2504 KB Output is correct
28 Correct 61 ms 2504 KB Output is correct
29 Correct 392 ms 2504 KB Output is correct
30 Correct 448 ms 2504 KB Output is correct
31 Correct 23 ms 2504 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 51 ms 1484 KB Output is correct
34 Correct 54 ms 2500 KB Output is correct
35 Correct 11 ms 680 KB Output is correct
36 Correct 35 ms 1428 KB Output is correct
37 Correct 60 ms 2504 KB Output is correct
38 Correct 54 ms 2468 KB Output is correct
39 Correct 11 ms 1484 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 349 ms 2424 KB Output is correct
42 Correct 68 ms 2504 KB Output is correct
43 Correct 176 ms 2504 KB Output is correct
44 Correct 62 ms 2400 KB Output is correct
45 Correct 33 ms 2504 KB Output is correct
46 Correct 393 ms 2472 KB Output is correct
47 Correct 29 ms 2504 KB Output is correct
48 Correct 123 ms 2416 KB Output is correct
49 Correct 59 ms 2488 KB Output is correct
50 Execution timed out 2051 ms 2384 KB Time limit exceeded
51 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 22 ms 1484 KB Output is correct
10 Correct 6 ms 904 KB Output is correct
11 Correct 14 ms 1384 KB Output is correct
12 Correct 19 ms 1444 KB Output is correct
13 Correct 20 ms 1380 KB Output is correct
14 Correct 13 ms 1436 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
16 Correct 13 ms 1484 KB Output is correct
17 Correct 31 ms 2508 KB Output is correct
18 Correct 19 ms 1440 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 16 ms 976 KB Output is correct
35 Correct 24 ms 2504 KB Output is correct
36 Correct 61 ms 2504 KB Output is correct
37 Correct 392 ms 2504 KB Output is correct
38 Correct 448 ms 2504 KB Output is correct
39 Correct 23 ms 2504 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 51 ms 1484 KB Output is correct
42 Correct 54 ms 2500 KB Output is correct
43 Correct 11 ms 680 KB Output is correct
44 Correct 35 ms 1428 KB Output is correct
45 Correct 60 ms 2504 KB Output is correct
46 Correct 54 ms 2468 KB Output is correct
47 Correct 11 ms 1484 KB Output is correct
48 Correct 2 ms 332 KB Output is correct
49 Correct 349 ms 2424 KB Output is correct
50 Correct 68 ms 2504 KB Output is correct
51 Correct 176 ms 2504 KB Output is correct
52 Correct 62 ms 2400 KB Output is correct
53 Correct 33 ms 2504 KB Output is correct
54 Correct 393 ms 2472 KB Output is correct
55 Correct 29 ms 2504 KB Output is correct
56 Correct 123 ms 2416 KB Output is correct
57 Correct 59 ms 2488 KB Output is correct
58 Execution timed out 2051 ms 2384 KB Time limit exceeded
59 Halted 0 ms 0 KB -