Submission #706573

# Submission time Handle Problem Language Result Execution time Memory
706573 2023-03-07T05:11:54 Z LittleCube Chessboard (IZhO18_chessboard) C++14
70 / 100
677 ms 5808 KB
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;

ll N, K, l[100005], d[100005], r[100005], u[100005];
ll ans;

pll operator+(pll p1, pll p2)
{
    return pll(p1.F + p2.F, p1.S + p2.S);
}

bool isB(int x, int y, int M)
{
    return (x / M + y / M) % 2;
}

pll calcCorner(ll L, ll R, ll D, ll U, int M)
{
    if (isB(L, D, M))
        return pll((R - L) * (U - D), 0);
    else
        return pll(0, (R - L) * (U - D));
}

pll calcColumn(ll L, ll R, ll D, ll U, int M)
{
    pll res;
    ll blocks = (U - D) / M;
    if (blocks % 2 == 1)
        res = pll((R - L) * (blocks / 2 + 1) * M, (R - L) * (blocks / 2) * M);
    else
        res = pll((R - L) * (blocks / 2) * M, (R - L) * (blocks / 2) * M);
    if (!isB(L, D, M) && blocks % 2 == 1)
        swap(res.F, res.S);
    return res;
}

pll calcBlock(ll L, ll R, ll D, ll U, ll M)
{
    pll res;
    ll blocks = (R - L) * (U - D) / M / M;
    if (blocks % 2 == 1)
        res = pll(M * M * (blocks / 2 + 1), M * M * (blocks / 2));
    else
        res = pll(M * M * (blocks / 2), M * M * (blocks / 2));
    if (!isB(L, D, M) && blocks % 2 == 1)
        swap(res.F, res.S);
    return res;
}

void solve(int M)
{
    pll res = pll(0, 0), board = calcBlock(0, N, 0, N, M);
    for (int i = 1; i <= K; i++)
    {
        ll mL = (l[i] + M - 1) / M * M,
           mR = r[i] / M * M,
           mD = (d[i] + M - 1) / M * M,
           mU = u[i] / M * M;
        pll cur;
        if (mL > mR && mD > mU)
            cur = calcCorner(l[i], r[i], d[i], u[i], M);
        else if (mL > mR)
            cur = calcCorner(l[i], r[i], d[i], mD, M) +
                  calcColumn(l[i], r[i], mD, mU, M) +
                  calcCorner(l[i], r[i], mU, u[i], M);
        else if (mD > mU)
            cur = calcCorner(l[i], mL, d[i], u[i], M) +
                  calcColumn(mL, mR, d[i], u[i], M) +
                  calcCorner(mR, r[i], d[i], u[i], M);
        else
            cur = calcCorner(l[i], mL, d[i], mD, M) + calcColumn(d[i], mD, mL, mR, M) + calcCorner(mR, r[i], d[i], mD, M) +
                  calcColumn(l[i], mL, mD, mU, M) + calcBlock(mL, mR, mD, mU, M) + calcColumn(mR, r[i], mD, mU, M) +
                  calcCorner(l[i], mL, mU, u[i], M) + calcColumn(mU, u[i], mL, mR, M) + calcCorner(mR, r[i], mU, u[i], M);
        res = res + cur;
    }
    // cerr << M << ' ' << board.F << ' ' << board.S << '\n';
    ans = min({ans, board.F - res.F + res.S, res.F + board.S - res.S});
}

signed main()
{
    cin >> N >> K;
    ans = N * N;
    for (int i = 1; i <= K; i++)
    {
        cin >> l[i] >> d[i] >> r[i] >> u[i];
        l[i]--, d[i]--;
    }
    for (int i = 1; i < N; i++)
        if (N % i == 0)
            solve(i);
    cout << ans << '\n';
}

/*
6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 3704 KB Output is correct
2 Correct 20 ms 1092 KB Output is correct
3 Correct 46 ms 2464 KB Output is correct
4 Correct 48 ms 2600 KB Output is correct
5 Correct 63 ms 3252 KB Output is correct
6 Correct 41 ms 2124 KB Output is correct
7 Correct 9 ms 596 KB Output is correct
8 Correct 41 ms 2108 KB Output is correct
9 Correct 102 ms 5176 KB Output is correct
10 Correct 71 ms 3000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 352 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 352 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 29 ms 1492 KB Output is correct
17 Correct 77 ms 4244 KB Output is correct
18 Correct 99 ms 4992 KB Output is correct
19 Correct 189 ms 4488 KB Output is correct
20 Correct 203 ms 4872 KB Output is correct
21 Correct 74 ms 4100 KB Output is correct
22 Correct 1 ms 316 KB Output is correct
23 Correct 53 ms 2416 KB Output is correct
24 Correct 95 ms 4584 KB Output is correct
25 Correct 11 ms 724 KB Output is correct
26 Correct 56 ms 2988 KB Output is correct
27 Correct 79 ms 3528 KB Output is correct
28 Correct 101 ms 4836 KB Output is correct
29 Correct 32 ms 1868 KB Output is correct
30 Correct 4 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 3704 KB Output is correct
2 Correct 20 ms 1092 KB Output is correct
3 Correct 46 ms 2464 KB Output is correct
4 Correct 48 ms 2600 KB Output is correct
5 Correct 63 ms 3252 KB Output is correct
6 Correct 41 ms 2124 KB Output is correct
7 Correct 9 ms 596 KB Output is correct
8 Correct 41 ms 2108 KB Output is correct
9 Correct 102 ms 5176 KB Output is correct
10 Correct 71 ms 3000 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 352 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 316 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 29 ms 1492 KB Output is correct
27 Correct 77 ms 4244 KB Output is correct
28 Correct 99 ms 4992 KB Output is correct
29 Correct 189 ms 4488 KB Output is correct
30 Correct 203 ms 4872 KB Output is correct
31 Correct 74 ms 4100 KB Output is correct
32 Correct 1 ms 316 KB Output is correct
33 Correct 53 ms 2416 KB Output is correct
34 Correct 95 ms 4584 KB Output is correct
35 Correct 11 ms 724 KB Output is correct
36 Correct 56 ms 2988 KB Output is correct
37 Correct 79 ms 3528 KB Output is correct
38 Correct 101 ms 4836 KB Output is correct
39 Correct 32 ms 1868 KB Output is correct
40 Correct 4 ms 340 KB Output is correct
41 Correct 176 ms 4788 KB Output is correct
42 Correct 119 ms 5388 KB Output is correct
43 Correct 137 ms 4896 KB Output is correct
44 Correct 130 ms 5264 KB Output is correct
45 Correct 113 ms 5708 KB Output is correct
46 Correct 197 ms 5424 KB Output is correct
47 Correct 107 ms 4996 KB Output is correct
48 Correct 125 ms 5108 KB Output is correct
49 Correct 104 ms 4920 KB Output is correct
50 Correct 580 ms 5304 KB Output is correct
51 Correct 618 ms 5644 KB Output is correct
52 Correct 560 ms 5272 KB Output is correct
53 Correct 599 ms 5608 KB Output is correct
54 Correct 556 ms 5208 KB Output is correct
55 Correct 644 ms 5808 KB Output is correct
56 Correct 552 ms 5052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 73 ms 3704 KB Output is correct
10 Correct 20 ms 1092 KB Output is correct
11 Correct 46 ms 2464 KB Output is correct
12 Correct 48 ms 2600 KB Output is correct
13 Correct 63 ms 3252 KB Output is correct
14 Correct 41 ms 2124 KB Output is correct
15 Correct 9 ms 596 KB Output is correct
16 Correct 41 ms 2108 KB Output is correct
17 Correct 102 ms 5176 KB Output is correct
18 Correct 71 ms 3000 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 352 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 316 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 29 ms 1492 KB Output is correct
35 Correct 77 ms 4244 KB Output is correct
36 Correct 99 ms 4992 KB Output is correct
37 Correct 189 ms 4488 KB Output is correct
38 Correct 203 ms 4872 KB Output is correct
39 Correct 74 ms 4100 KB Output is correct
40 Correct 1 ms 316 KB Output is correct
41 Correct 53 ms 2416 KB Output is correct
42 Correct 95 ms 4584 KB Output is correct
43 Correct 11 ms 724 KB Output is correct
44 Correct 56 ms 2988 KB Output is correct
45 Correct 79 ms 3528 KB Output is correct
46 Correct 101 ms 4836 KB Output is correct
47 Correct 32 ms 1868 KB Output is correct
48 Correct 4 ms 340 KB Output is correct
49 Correct 176 ms 4788 KB Output is correct
50 Correct 119 ms 5388 KB Output is correct
51 Correct 137 ms 4896 KB Output is correct
52 Correct 130 ms 5264 KB Output is correct
53 Correct 113 ms 5708 KB Output is correct
54 Correct 197 ms 5424 KB Output is correct
55 Correct 107 ms 4996 KB Output is correct
56 Correct 125 ms 5108 KB Output is correct
57 Correct 104 ms 4920 KB Output is correct
58 Correct 580 ms 5304 KB Output is correct
59 Correct 618 ms 5644 KB Output is correct
60 Correct 560 ms 5272 KB Output is correct
61 Correct 599 ms 5608 KB Output is correct
62 Correct 556 ms 5208 KB Output is correct
63 Correct 644 ms 5808 KB Output is correct
64 Correct 552 ms 5052 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Incorrect 677 ms 5520 KB Output isn't correct
68 Halted 0 ms 0 KB -