답안 #523570

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
523570 2022-02-07T19:35:16 Z RaresFelix Chessboard (IZhO18_chessboard) C++17
47 / 100
2000 ms 2556 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.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";
}
# 결과 실행 시간 메모리 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 1 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 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 1368 KB Output is correct
2 Correct 9 ms 976 KB Output is correct
3 Correct 22 ms 1472 KB Output is correct
4 Correct 15 ms 1484 KB Output is correct
5 Correct 18 ms 1484 KB Output is correct
6 Correct 13 ms 1364 KB Output is correct
7 Correct 3 ms 460 KB Output is correct
8 Correct 14 ms 1484 KB Output is correct
9 Correct 32 ms 2408 KB Output is correct
10 Correct 18 ms 1436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 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 2 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 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 2 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 17 ms 976 KB Output is correct
17 Correct 26 ms 2436 KB Output is correct
18 Correct 62 ms 2492 KB Output is correct
19 Correct 403 ms 2484 KB Output is correct
20 Correct 436 ms 2504 KB Output is correct
21 Correct 26 ms 2504 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 52 ms 1484 KB Output is correct
24 Correct 55 ms 2524 KB Output is correct
25 Correct 11 ms 588 KB Output is correct
26 Correct 34 ms 1484 KB Output is correct
27 Correct 58 ms 2504 KB Output is correct
28 Correct 53 ms 2392 KB Output is correct
29 Correct 15 ms 1484 KB Output is correct
30 Correct 3 ms 424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 1368 KB Output is correct
2 Correct 9 ms 976 KB Output is correct
3 Correct 22 ms 1472 KB Output is correct
4 Correct 15 ms 1484 KB Output is correct
5 Correct 18 ms 1484 KB Output is correct
6 Correct 13 ms 1364 KB Output is correct
7 Correct 3 ms 460 KB Output is correct
8 Correct 14 ms 1484 KB Output is correct
9 Correct 32 ms 2408 KB Output is correct
10 Correct 18 ms 1436 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 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 2 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 17 ms 976 KB Output is correct
27 Correct 26 ms 2436 KB Output is correct
28 Correct 62 ms 2492 KB Output is correct
29 Correct 403 ms 2484 KB Output is correct
30 Correct 436 ms 2504 KB Output is correct
31 Correct 26 ms 2504 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 52 ms 1484 KB Output is correct
34 Correct 55 ms 2524 KB Output is correct
35 Correct 11 ms 588 KB Output is correct
36 Correct 34 ms 1484 KB Output is correct
37 Correct 58 ms 2504 KB Output is correct
38 Correct 53 ms 2392 KB Output is correct
39 Correct 15 ms 1484 KB Output is correct
40 Correct 3 ms 424 KB Output is correct
41 Correct 349 ms 2384 KB Output is correct
42 Correct 66 ms 2516 KB Output is correct
43 Correct 178 ms 2504 KB Output is correct
44 Correct 64 ms 2504 KB Output is correct
45 Correct 35 ms 2504 KB Output is correct
46 Correct 400 ms 2504 KB Output is correct
47 Correct 30 ms 2504 KB Output is correct
48 Correct 125 ms 2392 KB Output is correct
49 Correct 59 ms 2428 KB Output is correct
50 Execution timed out 2072 ms 2556 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 1 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 1 ms 204 KB Output is correct
9 Correct 23 ms 1368 KB Output is correct
10 Correct 9 ms 976 KB Output is correct
11 Correct 22 ms 1472 KB Output is correct
12 Correct 15 ms 1484 KB Output is correct
13 Correct 18 ms 1484 KB Output is correct
14 Correct 13 ms 1364 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
16 Correct 14 ms 1484 KB Output is correct
17 Correct 32 ms 2408 KB Output is correct
18 Correct 18 ms 1436 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 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 2 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 17 ms 976 KB Output is correct
35 Correct 26 ms 2436 KB Output is correct
36 Correct 62 ms 2492 KB Output is correct
37 Correct 403 ms 2484 KB Output is correct
38 Correct 436 ms 2504 KB Output is correct
39 Correct 26 ms 2504 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 52 ms 1484 KB Output is correct
42 Correct 55 ms 2524 KB Output is correct
43 Correct 11 ms 588 KB Output is correct
44 Correct 34 ms 1484 KB Output is correct
45 Correct 58 ms 2504 KB Output is correct
46 Correct 53 ms 2392 KB Output is correct
47 Correct 15 ms 1484 KB Output is correct
48 Correct 3 ms 424 KB Output is correct
49 Correct 349 ms 2384 KB Output is correct
50 Correct 66 ms 2516 KB Output is correct
51 Correct 178 ms 2504 KB Output is correct
52 Correct 64 ms 2504 KB Output is correct
53 Correct 35 ms 2504 KB Output is correct
54 Correct 400 ms 2504 KB Output is correct
55 Correct 30 ms 2504 KB Output is correct
56 Correct 125 ms 2392 KB Output is correct
57 Correct 59 ms 2428 KB Output is correct
58 Execution timed out 2072 ms 2556 KB Time limit exceeded
59 Halted 0 ms 0 KB -