Submission #173862

# Submission time Handle Problem Language Result Execution time Memory
173862 2020-01-05T15:43:42 Z VEGAnn Chessboard (IZhO18_chessboard) C++14
62 / 100
1853 ms 4368 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;

    if (k == 0){
        for (int i = n - 1; ;i--)
            if (n % i == 0){
                n /= i;
                int res = (n * n) / 2;
                cout << res * i * i;
                break;
            }
        return 0;
    }

    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 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 37 ms 1400 KB Output is correct
2 Correct 12 ms 656 KB Output is correct
3 Correct 24 ms 1016 KB Output is correct
4 Correct 26 ms 1148 KB Output is correct
5 Correct 34 ms 1284 KB Output is correct
6 Correct 23 ms 888 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 22 ms 1016 KB Output is correct
9 Correct 54 ms 1784 KB Output is correct
10 Correct 33 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 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 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 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 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 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 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 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 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 23 ms 1144 KB Output is correct
17 Correct 43 ms 3036 KB Output is correct
18 Correct 78 ms 3448 KB Output is correct
19 Correct 378 ms 3216 KB Output is correct
20 Correct 423 ms 3576 KB Output is correct
21 Correct 40 ms 2936 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 59 ms 1656 KB Output is correct
24 Correct 71 ms 3192 KB Output is correct
25 Correct 14 ms 632 KB Output is correct
26 Correct 46 ms 2168 KB Output is correct
27 Correct 74 ms 2556 KB Output is correct
28 Correct 75 ms 3472 KB Output is correct
29 Correct 18 ms 1528 KB Output is correct
30 Correct 4 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 1400 KB Output is correct
2 Correct 12 ms 656 KB Output is correct
3 Correct 24 ms 1016 KB Output is correct
4 Correct 26 ms 1148 KB Output is correct
5 Correct 34 ms 1284 KB Output is correct
6 Correct 23 ms 888 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 22 ms 1016 KB Output is correct
9 Correct 54 ms 1784 KB Output is correct
10 Correct 33 ms 1144 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 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 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 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 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 23 ms 1144 KB Output is correct
27 Correct 43 ms 3036 KB Output is correct
28 Correct 78 ms 3448 KB Output is correct
29 Correct 378 ms 3216 KB Output is correct
30 Correct 423 ms 3576 KB Output is correct
31 Correct 40 ms 2936 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 59 ms 1656 KB Output is correct
34 Correct 71 ms 3192 KB Output is correct
35 Correct 14 ms 632 KB Output is correct
36 Correct 46 ms 2168 KB Output is correct
37 Correct 74 ms 2556 KB Output is correct
38 Correct 75 ms 3472 KB Output is correct
39 Correct 18 ms 1528 KB Output is correct
40 Correct 4 ms 504 KB Output is correct
41 Correct 310 ms 3720 KB Output is correct
42 Correct 80 ms 4088 KB Output is correct
43 Correct 168 ms 3708 KB Output is correct
44 Correct 80 ms 3960 KB Output is correct
45 Correct 56 ms 4216 KB Output is correct
46 Correct 346 ms 4108 KB Output is correct
47 Correct 49 ms 3704 KB Output is correct
48 Correct 125 ms 3832 KB Output is correct
49 Correct 72 ms 3704 KB Output is correct
50 Correct 1815 ms 3932 KB Output is correct
51 Correct 1798 ms 4244 KB Output is correct
52 Correct 1678 ms 3960 KB Output is correct
53 Correct 1792 ms 4216 KB Output is correct
54 Correct 1652 ms 3836 KB Output is correct
55 Correct 1853 ms 4368 KB Output is correct
56 Correct 1599 ms 3832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -