답안 #173864

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
173864 2020-01-05T15:47:05 Z VEGAnn Chessboard (IZhO18_chessboard) C++14
100 / 100
1722 ms 4348 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) >> 1) * gl * (((ko + 1) >> 1) * gl + ad1);
    res += ((kl + 0) >> 1) * gl * (((ko + 0) >> 1) * gl + ad2);

    if (y % gl > 0){
        if (kl % 2 == 0)
            res += (((ko + 1) >> 1) * gl + ad1) * (y % gl);
        else res += (((ko + 0) >> 1) * 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;
}
# 결과 실행 시간 메모리 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 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 2552 KB Output is correct
2 Correct 11 ms 632 KB Output is correct
3 Correct 24 ms 1756 KB Output is correct
4 Correct 26 ms 1144 KB Output is correct
5 Correct 32 ms 1272 KB Output is correct
6 Correct 22 ms 1528 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 21 ms 916 KB Output is correct
9 Correct 52 ms 3064 KB Output is correct
10 Correct 30 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 348 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 348 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 22 ms 760 KB Output is correct
17 Correct 43 ms 3076 KB Output is correct
18 Correct 75 ms 2040 KB Output is correct
19 Correct 356 ms 1884 KB Output is correct
20 Correct 393 ms 2040 KB Output is correct
21 Correct 40 ms 1656 KB Output is correct
22 Correct 3 ms 380 KB Output is correct
23 Correct 56 ms 1016 KB Output is correct
24 Correct 68 ms 1756 KB Output is correct
25 Correct 13 ms 508 KB Output is correct
26 Correct 44 ms 2168 KB Output is correct
27 Correct 71 ms 1456 KB Output is correct
28 Correct 72 ms 2040 KB Output is correct
29 Correct 18 ms 888 KB Output is correct
30 Correct 4 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 2552 KB Output is correct
2 Correct 11 ms 632 KB Output is correct
3 Correct 24 ms 1756 KB Output is correct
4 Correct 26 ms 1144 KB Output is correct
5 Correct 32 ms 1272 KB Output is correct
6 Correct 22 ms 1528 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 21 ms 916 KB Output is correct
9 Correct 52 ms 3064 KB Output is correct
10 Correct 30 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 3 ms 348 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 22 ms 760 KB Output is correct
27 Correct 43 ms 3076 KB Output is correct
28 Correct 75 ms 2040 KB Output is correct
29 Correct 356 ms 1884 KB Output is correct
30 Correct 393 ms 2040 KB Output is correct
31 Correct 40 ms 1656 KB Output is correct
32 Correct 3 ms 380 KB Output is correct
33 Correct 56 ms 1016 KB Output is correct
34 Correct 68 ms 1756 KB Output is correct
35 Correct 13 ms 508 KB Output is correct
36 Correct 44 ms 2168 KB Output is correct
37 Correct 71 ms 1456 KB Output is correct
38 Correct 72 ms 2040 KB Output is correct
39 Correct 18 ms 888 KB Output is correct
40 Correct 4 ms 376 KB Output is correct
41 Correct 290 ms 3680 KB Output is correct
42 Correct 78 ms 1784 KB Output is correct
43 Correct 160 ms 3452 KB Output is correct
44 Correct 76 ms 1912 KB Output is correct
45 Correct 55 ms 4216 KB Output is correct
46 Correct 323 ms 3104 KB Output is correct
47 Correct 48 ms 2040 KB Output is correct
48 Correct 119 ms 3192 KB Output is correct
49 Correct 70 ms 3448 KB Output is correct
50 Correct 1563 ms 3184 KB Output is correct
51 Correct 1679 ms 4236 KB Output is correct
52 Correct 1552 ms 3792 KB Output is correct
53 Correct 1658 ms 4216 KB Output is correct
54 Correct 1529 ms 3832 KB Output is correct
55 Correct 1718 ms 4348 KB Output is correct
56 Correct 1545 ms 3876 KB Output is correct
# 결과 실행 시간 메모리 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 380 KB Output is correct
9 Correct 36 ms 2552 KB Output is correct
10 Correct 11 ms 632 KB Output is correct
11 Correct 24 ms 1756 KB Output is correct
12 Correct 26 ms 1144 KB Output is correct
13 Correct 32 ms 1272 KB Output is correct
14 Correct 22 ms 1528 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
16 Correct 21 ms 916 KB Output is correct
17 Correct 52 ms 3064 KB Output is correct
18 Correct 30 ms 1144 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 348 KB Output is correct
22 Correct 3 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 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 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 376 KB Output is correct
33 Correct 3 ms 376 KB Output is correct
34 Correct 22 ms 760 KB Output is correct
35 Correct 43 ms 3076 KB Output is correct
36 Correct 75 ms 2040 KB Output is correct
37 Correct 356 ms 1884 KB Output is correct
38 Correct 393 ms 2040 KB Output is correct
39 Correct 40 ms 1656 KB Output is correct
40 Correct 3 ms 380 KB Output is correct
41 Correct 56 ms 1016 KB Output is correct
42 Correct 68 ms 1756 KB Output is correct
43 Correct 13 ms 508 KB Output is correct
44 Correct 44 ms 2168 KB Output is correct
45 Correct 71 ms 1456 KB Output is correct
46 Correct 72 ms 2040 KB Output is correct
47 Correct 18 ms 888 KB Output is correct
48 Correct 4 ms 376 KB Output is correct
49 Correct 290 ms 3680 KB Output is correct
50 Correct 78 ms 1784 KB Output is correct
51 Correct 160 ms 3452 KB Output is correct
52 Correct 76 ms 1912 KB Output is correct
53 Correct 55 ms 4216 KB Output is correct
54 Correct 323 ms 3104 KB Output is correct
55 Correct 48 ms 2040 KB Output is correct
56 Correct 119 ms 3192 KB Output is correct
57 Correct 70 ms 3448 KB Output is correct
58 Correct 1563 ms 3184 KB Output is correct
59 Correct 1679 ms 4236 KB Output is correct
60 Correct 1552 ms 3792 KB Output is correct
61 Correct 1658 ms 4216 KB Output is correct
62 Correct 1529 ms 3832 KB Output is correct
63 Correct 1718 ms 4348 KB Output is correct
64 Correct 1545 ms 3876 KB Output is correct
65 Correct 2 ms 376 KB Output is correct
66 Correct 2 ms 376 KB Output is correct
67 Correct 1618 ms 3272 KB Output is correct
68 Correct 1624 ms 3212 KB Output is correct
69 Correct 1408 ms 3072 KB Output is correct
70 Correct 1541 ms 3204 KB Output is correct
71 Correct 1562 ms 3192 KB Output is correct
72 Correct 1493 ms 3192 KB Output is correct
73 Correct 1480 ms 3136 KB Output is correct
74 Correct 1617 ms 3260 KB Output is correct
75 Correct 1509 ms 3172 KB Output is correct
76 Correct 1619 ms 3192 KB Output is correct
77 Correct 239 ms 3448 KB Output is correct
78 Correct 76 ms 3320 KB Output is correct
79 Correct 163 ms 3064 KB Output is correct
80 Correct 170 ms 3320 KB Output is correct
81 Correct 157 ms 3116 KB Output is correct
82 Correct 130 ms 1912 KB Output is correct
83 Correct 93 ms 3064 KB Output is correct
84 Correct 952 ms 3400 KB Output is correct
85 Correct 1722 ms 3356 KB Output is correct
86 Correct 3 ms 376 KB Output is correct
87 Correct 2 ms 376 KB Output is correct
88 Correct 1720 ms 3448 KB Output is correct
89 Correct 322 ms 1144 KB Output is correct
90 Correct 2 ms 376 KB Output is correct