Submission #173863

# Submission time Handle Problem Language Result Execution time Memory
173863 2020-01-05T15:44:21 Z VEGAnn Chessboard (IZhO18_chessboard) C++14
100 / 100
1859 ms 4444 KB
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pii pair<int, int>
#define ft first
#define sd second
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long ll;
const int oo = 2e9;
const ll OO = 1e18;
const int N = 100100;
ll ans = OO, gl;
int x1[N], Y1[N], x2[N], y2[N], n, k;

ll calc(ll x, ll y){
    if (x <= 0 || y <= 0) return 0;
    ll kl = y / gl, res = 0;
    ll ko = x / gl;

    ll ad1 = 0, ad2 = 0;

    if (x % gl > 0){
        if (ko % 2 == 0)
            ad1 += x % gl;
        else ad2 += x % gl;
    }

    res += ((kl + 1) / 2ll) * gl * ((ko + 1) / 2ll * gl + ad1);
    res += ((kl + 0) / 2ll) * gl * ((ko + 0) / 2ll * gl + ad2);

    if (y % gl > 0){
        if (kl % 2 == 0)
            res += ((ko + 1) / 2ll * gl + ad1) * (y % gl);
        else res += ((ko + 0) / 2ll * gl + ad2) * (y % gl);
    }

    return res;
}

ll calc(ll x1, ll Y1, ll x2, ll y2){
    return calc(x2, y2) - calc(x1 - 1, y2) - calc(x2, Y1 - 1) + calc(x1 - 1, Y1 - 1);
}

ll check(ll x){
    gl = x;
    ll cnd1 = calc(n, n);
    ll cnd2 = ll(n) * ll(n) - cnd1;

    for (int i = 0; i < k; i++){
        ll k1 = calc(x1[i], Y1[i], x2[i], y2[i]);
        ll x = x2[i] - x1[i] + 1;
        ll y = y2[i] - Y1[i] + 1;
        cnd1 -= k1 - (x * y - k1);
        cnd2 -= - k1 + (x * y - k1);
    }

    return min(cnd1, cnd2);
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> n >> k;

    for (int i = 0; i < k; i++)
        cin >> x1[i] >> Y1[i] >> x2[i] >> y2[i];

    int root = (int)trunc(sqrt(n));
    for (int i = 1; i <= root; i++)
        if (n % i == 0){
            ans = min(ans, check(i));
            if (i != 1)
                ans = min(ans, check(n / i));
        }

    cout << ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 2552 KB Output is correct
2 Correct 11 ms 632 KB Output is correct
3 Correct 24 ms 1656 KB Output is correct
4 Correct 26 ms 1240 KB Output is correct
5 Correct 32 ms 1272 KB Output is correct
6 Correct 22 ms 1588 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 22 ms 888 KB Output is correct
9 Correct 53 ms 2936 KB Output is correct
10 Correct 30 ms 1400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 1 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 380 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 0 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 380 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 1 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 380 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 0 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 380 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 24 ms 760 KB Output is correct
17 Correct 42 ms 3040 KB Output is correct
18 Correct 78 ms 2952 KB Output is correct
19 Correct 376 ms 1780 KB Output is correct
20 Correct 421 ms 2040 KB Output is correct
21 Correct 41 ms 1656 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 59 ms 1020 KB Output is correct
24 Correct 71 ms 1808 KB Output is correct
25 Correct 13 ms 504 KB Output is correct
26 Correct 46 ms 2168 KB Output is correct
27 Correct 76 ms 1376 KB Output is correct
28 Correct 75 ms 3064 KB Output is correct
29 Correct 19 ms 888 KB Output is correct
30 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 2552 KB Output is correct
2 Correct 11 ms 632 KB Output is correct
3 Correct 24 ms 1656 KB Output is correct
4 Correct 26 ms 1240 KB Output is correct
5 Correct 32 ms 1272 KB Output is correct
6 Correct 22 ms 1588 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 22 ms 888 KB Output is correct
9 Correct 53 ms 2936 KB Output is correct
10 Correct 30 ms 1400 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 1 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 380 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 0 ms 376 KB Output is correct
20 Correct 2 ms 380 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 380 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 24 ms 760 KB Output is correct
27 Correct 42 ms 3040 KB Output is correct
28 Correct 78 ms 2952 KB Output is correct
29 Correct 376 ms 1780 KB Output is correct
30 Correct 421 ms 2040 KB Output is correct
31 Correct 41 ms 1656 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 59 ms 1020 KB Output is correct
34 Correct 71 ms 1808 KB Output is correct
35 Correct 13 ms 504 KB Output is correct
36 Correct 46 ms 2168 KB Output is correct
37 Correct 76 ms 1376 KB Output is correct
38 Correct 75 ms 3064 KB Output is correct
39 Correct 19 ms 888 KB Output is correct
40 Correct 4 ms 376 KB Output is correct
41 Correct 312 ms 3064 KB Output is correct
42 Correct 86 ms 1784 KB Output is correct
43 Correct 167 ms 3036 KB Output is correct
44 Correct 79 ms 1784 KB Output is correct
45 Correct 56 ms 3248 KB Output is correct
46 Correct 347 ms 3320 KB Output is correct
47 Correct 50 ms 2040 KB Output is correct
48 Correct 124 ms 3064 KB Output is correct
49 Correct 72 ms 3108 KB Output is correct
50 Correct 1690 ms 3184 KB Output is correct
51 Correct 1796 ms 3320 KB Output is correct
52 Correct 1806 ms 3220 KB Output is correct
53 Correct 1785 ms 3448 KB Output is correct
54 Correct 1651 ms 3192 KB Output is correct
55 Correct 1855 ms 3364 KB Output is correct
56 Correct 1606 ms 3064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 37 ms 2552 KB Output is correct
10 Correct 11 ms 632 KB Output is correct
11 Correct 24 ms 1656 KB Output is correct
12 Correct 26 ms 1240 KB Output is correct
13 Correct 32 ms 1272 KB Output is correct
14 Correct 22 ms 1588 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
16 Correct 22 ms 888 KB Output is correct
17 Correct 53 ms 2936 KB Output is correct
18 Correct 30 ms 1400 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 1 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 380 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 0 ms 376 KB Output is correct
28 Correct 2 ms 380 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 3 ms 380 KB Output is correct
33 Correct 3 ms 376 KB Output is correct
34 Correct 24 ms 760 KB Output is correct
35 Correct 42 ms 3040 KB Output is correct
36 Correct 78 ms 2952 KB Output is correct
37 Correct 376 ms 1780 KB Output is correct
38 Correct 421 ms 2040 KB Output is correct
39 Correct 41 ms 1656 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 59 ms 1020 KB Output is correct
42 Correct 71 ms 1808 KB Output is correct
43 Correct 13 ms 504 KB Output is correct
44 Correct 46 ms 2168 KB Output is correct
45 Correct 76 ms 1376 KB Output is correct
46 Correct 75 ms 3064 KB Output is correct
47 Correct 19 ms 888 KB Output is correct
48 Correct 4 ms 376 KB Output is correct
49 Correct 312 ms 3064 KB Output is correct
50 Correct 86 ms 1784 KB Output is correct
51 Correct 167 ms 3036 KB Output is correct
52 Correct 79 ms 1784 KB Output is correct
53 Correct 56 ms 3248 KB Output is correct
54 Correct 347 ms 3320 KB Output is correct
55 Correct 50 ms 2040 KB Output is correct
56 Correct 124 ms 3064 KB Output is correct
57 Correct 72 ms 3108 KB Output is correct
58 Correct 1690 ms 3184 KB Output is correct
59 Correct 1796 ms 3320 KB Output is correct
60 Correct 1806 ms 3220 KB Output is correct
61 Correct 1785 ms 3448 KB Output is correct
62 Correct 1651 ms 3192 KB Output is correct
63 Correct 1855 ms 3364 KB Output is correct
64 Correct 1606 ms 3064 KB Output is correct
65 Correct 2 ms 376 KB Output is correct
66 Correct 2 ms 376 KB Output is correct
67 Correct 1744 ms 4188 KB Output is correct
68 Correct 1742 ms 3960 KB Output is correct
69 Correct 1506 ms 3636 KB Output is correct
70 Correct 1662 ms 4004 KB Output is correct
71 Correct 1649 ms 3952 KB Output is correct
72 Correct 1607 ms 3960 KB Output is correct
73 Correct 1589 ms 3768 KB Output is correct
74 Correct 1730 ms 4036 KB Output is correct
75 Correct 1631 ms 3888 KB Output is correct
76 Correct 1754 ms 4216 KB Output is correct
77 Correct 257 ms 4216 KB Output is correct
78 Correct 80 ms 3904 KB Output is correct
79 Correct 172 ms 3704 KB Output is correct
80 Correct 183 ms 3832 KB Output is correct
81 Correct 177 ms 3576 KB Output is correct
82 Correct 138 ms 4088 KB Output is correct
83 Correct 102 ms 3816 KB Output is correct
84 Correct 1025 ms 4344 KB Output is correct
85 Correct 1856 ms 4292 KB Output is correct
86 Correct 3 ms 376 KB Output is correct
87 Correct 2 ms 424 KB Output is correct
88 Correct 1859 ms 4444 KB Output is correct
89 Correct 348 ms 1144 KB Output is correct
90 Correct 2 ms 376 KB Output is correct