답안 #523569

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
523569 2022-02-07T19:34:30 Z RaresFelix Chessboard (IZhO18_chessboard) C++17
47 / 100
2000 ms 2512 KB
#include <bits/stdc++.h>
#define MN 107171

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

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 >> 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";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 1408 KB Output is correct
2 Correct 17 ms 840 KB Output is correct
3 Correct 42 ms 1408 KB Output is correct
4 Correct 45 ms 1468 KB Output is correct
5 Correct 57 ms 1424 KB Output is correct
6 Correct 36 ms 1340 KB Output is correct
7 Correct 8 ms 460 KB Output is correct
8 Correct 37 ms 1380 KB Output is correct
9 Correct 91 ms 2408 KB Output is correct
10 Correct 53 ms 1340 KB Output is correct
# 결과 실행 시간 메모리 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 3 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 2 ms 204 KB Output is correct
14 Correct 2 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 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 3 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 2 ms 204 KB Output is correct
14 Correct 2 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 31 ms 892 KB Output is correct
17 Correct 70 ms 2356 KB Output is correct
18 Correct 122 ms 2488 KB Output is correct
19 Correct 442 ms 2364 KB Output is correct
20 Correct 490 ms 2464 KB Output is correct
21 Correct 75 ms 2396 KB Output is correct
22 Correct 2 ms 204 KB Output is correct
23 Correct 77 ms 1340 KB Output is correct
24 Correct 103 ms 2448 KB Output is correct
25 Correct 16 ms 588 KB Output is correct
26 Correct 77 ms 1572 KB Output is correct
27 Correct 97 ms 2416 KB Output is correct
28 Correct 106 ms 2444 KB Output is correct
29 Correct 28 ms 1448 KB Output is correct
30 Correct 3 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 1408 KB Output is correct
2 Correct 17 ms 840 KB Output is correct
3 Correct 42 ms 1408 KB Output is correct
4 Correct 45 ms 1468 KB Output is correct
5 Correct 57 ms 1424 KB Output is correct
6 Correct 36 ms 1340 KB Output is correct
7 Correct 8 ms 460 KB Output is correct
8 Correct 37 ms 1380 KB Output is correct
9 Correct 91 ms 2408 KB Output is correct
10 Correct 53 ms 1340 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 3 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 2 ms 204 KB Output is correct
24 Correct 2 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 31 ms 892 KB Output is correct
27 Correct 70 ms 2356 KB Output is correct
28 Correct 122 ms 2488 KB Output is correct
29 Correct 442 ms 2364 KB Output is correct
30 Correct 490 ms 2464 KB Output is correct
31 Correct 75 ms 2396 KB Output is correct
32 Correct 2 ms 204 KB Output is correct
33 Correct 77 ms 1340 KB Output is correct
34 Correct 103 ms 2448 KB Output is correct
35 Correct 16 ms 588 KB Output is correct
36 Correct 77 ms 1572 KB Output is correct
37 Correct 97 ms 2416 KB Output is correct
38 Correct 106 ms 2444 KB Output is correct
39 Correct 28 ms 1448 KB Output is correct
40 Correct 3 ms 332 KB Output is correct
41 Correct 411 ms 2372 KB Output is correct
42 Correct 131 ms 2396 KB Output is correct
43 Correct 234 ms 2416 KB Output is correct
44 Correct 128 ms 2356 KB Output is correct
45 Correct 114 ms 2468 KB Output is correct
46 Correct 453 ms 2352 KB Output is correct
47 Correct 90 ms 2428 KB Output is correct
48 Correct 192 ms 2512 KB Output is correct
49 Correct 118 ms 2384 KB Output is correct
50 Execution timed out 2095 ms 2392 KB Time limit exceeded
51 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 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 69 ms 1408 KB Output is correct
10 Correct 17 ms 840 KB Output is correct
11 Correct 42 ms 1408 KB Output is correct
12 Correct 45 ms 1468 KB Output is correct
13 Correct 57 ms 1424 KB Output is correct
14 Correct 36 ms 1340 KB Output is correct
15 Correct 8 ms 460 KB Output is correct
16 Correct 37 ms 1380 KB Output is correct
17 Correct 91 ms 2408 KB Output is correct
18 Correct 53 ms 1340 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 3 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 2 ms 204 KB Output is correct
32 Correct 2 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 31 ms 892 KB Output is correct
35 Correct 70 ms 2356 KB Output is correct
36 Correct 122 ms 2488 KB Output is correct
37 Correct 442 ms 2364 KB Output is correct
38 Correct 490 ms 2464 KB Output is correct
39 Correct 75 ms 2396 KB Output is correct
40 Correct 2 ms 204 KB Output is correct
41 Correct 77 ms 1340 KB Output is correct
42 Correct 103 ms 2448 KB Output is correct
43 Correct 16 ms 588 KB Output is correct
44 Correct 77 ms 1572 KB Output is correct
45 Correct 97 ms 2416 KB Output is correct
46 Correct 106 ms 2444 KB Output is correct
47 Correct 28 ms 1448 KB Output is correct
48 Correct 3 ms 332 KB Output is correct
49 Correct 411 ms 2372 KB Output is correct
50 Correct 131 ms 2396 KB Output is correct
51 Correct 234 ms 2416 KB Output is correct
52 Correct 128 ms 2356 KB Output is correct
53 Correct 114 ms 2468 KB Output is correct
54 Correct 453 ms 2352 KB Output is correct
55 Correct 90 ms 2428 KB Output is correct
56 Correct 192 ms 2512 KB Output is correct
57 Correct 118 ms 2384 KB Output is correct
58 Execution timed out 2095 ms 2392 KB Time limit exceeded
59 Halted 0 ms 0 KB -