Submission #839762

# Submission time Handle Problem Language Result Execution time Memory
839762 2023-08-30T15:50:29 Z model_code Soccer Stadium (IOI23_soccer) C++17
100 / 100
2289 ms 131216 KB
// correct/sol_db_N2logN_1.cpp

#include "soccer.h"
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cassert>
#include <string.h>
#define xx first
#define yy second

using namespace std;
typedef pair<int, int> pii;
const int maxL = 10;
int N;

map<pair<int, pii>, int> dp;
vector<vector<int>> pre;

int query(int li, int lj, int ri, int rj)
{
    return pre[ri][rj] - (li ? pre[li - 1][rj] : 0) - (lj ? pre[ri][lj - 1] : 0) + (li && lj ? pre[li - 1][lj - 1] : 0);
}

pii calc_range(int i, int l, int r)
{
    int li = i - 1, ri = i;
    for (int j = maxL; j >= 0; --j)
    {
        while (li - (1 << j) >= 0 && query(li - (1 << j), l, i - 1, r) == 0)
        {
            li -= 1 << j;
        }
        while (ri + (1 << j) < N && query(i, l, ri + (1 << j), r) == 0)
        {
            ri += 1 << j;
        }
    }
    if (li >= 0 && query(li, l, i - 1, r) == 0)
        li--;
    if (ri < N && query(i, l, ri, r) == 0)
        ri++;
    return pii{li, ri};
}

int calc(int i, int l, int r)
{
    auto it = dp.find({i, {l, r}});
    if (it != dp.end())
    {
        return it->yy;
    }
    pii range = calc_range(i, l, r);
    if (i != range.xx + 1)
    {
        return calc(range.xx + 1, l, r);
    }
    int li = range.xx;
    int ri = range.yy;
    int res = 0;

    for (int L = l, R = l; R <= r; ++L, R = max(R, L))
    {
        auto extendable = [&](int R)
        {
            return (li >= 0 && query(li, L, i - 1, R) == 0) || (ri < N && query(i, L, ri, R) == 0);
        };
        for (int i = maxL; i >= 0; --i)
        {
            if (L + (1 << i) > R)
            {
                continue;
            }
            L += 1 << i;
            if (extendable(R))
                L -= 1 << i;
        }
        if (!extendable(R))
        {
            continue;
        }
        for (int i = maxL; i >= 0; --i)
        {
            if (R + (1 << i) <= r && extendable(R + (1 << i)))
            {
                R += 1 << i;
            }
        }
        pii range = calc_range(i, L, R);
        res = max(res, calc(i, L, R) + (R - L + 1) * (li - range.xx + range.yy - ri));
        R++;
    }
    return dp[{i, {l, r}}] = res;
}

int biggest_stadium(int n, vector<vector<int>> C)
{
    N = n, pre = C;
    for (int i = 0; i < N; ++i)
    {
        for (int j = 0; j < N; ++j)
        {
            pre[i][j] += (j ? pre[i][j - 1] : 0);
        }
    }
    for (int i = 0; i < N; ++i)
    {
        for (int j = 0; j < N; ++j)
        {
            pre[i][j] += (i ? pre[i - 1][j] : 0);
        }
    }
    int res = 0;
    for (int i = 0; i < N; ++i)
    {
        pii range = calc_range(i, 0, N - 1);
        res = max(res, calc(i, 0, N - 1) + N * (range.yy - range.xx - 1));
    }
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB ok
2 Correct 1 ms 240 KB ok
3 Correct 0 ms 212 KB ok
4 Correct 0 ms 212 KB ok
5 Correct 1 ms 256 KB ok
6 Correct 0 ms 212 KB ok
7 Correct 1 ms 340 KB ok
8 Correct 23 ms 3284 KB ok
9 Correct 385 ms 47444 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB ok
2 Correct 1 ms 240 KB ok
3 Correct 0 ms 232 KB ok
4 Correct 1 ms 212 KB ok
5 Correct 0 ms 212 KB ok
6 Correct 0 ms 212 KB ok
7 Correct 0 ms 212 KB ok
8 Correct 1 ms 212 KB ok
9 Correct 0 ms 212 KB ok
10 Correct 1 ms 212 KB ok
11 Correct 1 ms 212 KB ok
12 Correct 1 ms 212 KB ok
13 Correct 0 ms 212 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB ok
2 Correct 0 ms 212 KB ok
3 Correct 1 ms 240 KB ok
4 Correct 0 ms 232 KB ok
5 Correct 1 ms 212 KB ok
6 Correct 0 ms 212 KB ok
7 Correct 0 ms 212 KB ok
8 Correct 0 ms 212 KB ok
9 Correct 1 ms 212 KB ok
10 Correct 0 ms 212 KB ok
11 Correct 1 ms 212 KB ok
12 Correct 1 ms 212 KB ok
13 Correct 1 ms 212 KB ok
14 Correct 0 ms 212 KB ok
15 Correct 1 ms 212 KB ok
16 Correct 1 ms 212 KB ok
17 Correct 0 ms 212 KB ok
18 Correct 0 ms 212 KB ok
19 Correct 0 ms 212 KB ok
20 Correct 1 ms 212 KB ok
21 Correct 1 ms 212 KB ok
22 Correct 0 ms 212 KB ok
23 Correct 0 ms 212 KB ok
24 Correct 0 ms 212 KB ok
25 Correct 1 ms 212 KB ok
26 Correct 1 ms 212 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB ok
2 Correct 0 ms 212 KB ok
3 Correct 1 ms 240 KB ok
4 Correct 0 ms 212 KB ok
5 Correct 0 ms 212 KB ok
6 Correct 0 ms 232 KB ok
7 Correct 1 ms 212 KB ok
8 Correct 0 ms 212 KB ok
9 Correct 0 ms 212 KB ok
10 Correct 0 ms 212 KB ok
11 Correct 1 ms 212 KB ok
12 Correct 0 ms 212 KB ok
13 Correct 1 ms 212 KB ok
14 Correct 1 ms 212 KB ok
15 Correct 1 ms 212 KB ok
16 Correct 0 ms 212 KB ok
17 Correct 1 ms 212 KB ok
18 Correct 1 ms 212 KB ok
19 Correct 0 ms 212 KB ok
20 Correct 0 ms 212 KB ok
21 Correct 0 ms 212 KB ok
22 Correct 1 ms 212 KB ok
23 Correct 1 ms 212 KB ok
24 Correct 0 ms 212 KB ok
25 Correct 0 ms 212 KB ok
26 Correct 0 ms 212 KB ok
27 Correct 1 ms 212 KB ok
28 Correct 1 ms 212 KB ok
29 Correct 1 ms 212 KB ok
30 Correct 1 ms 212 KB ok
31 Correct 1 ms 212 KB ok
32 Correct 1 ms 212 KB ok
33 Correct 1 ms 256 KB ok
34 Correct 1 ms 212 KB ok
35 Correct 0 ms 212 KB ok
36 Correct 0 ms 212 KB ok
37 Correct 1 ms 212 KB ok
38 Correct 0 ms 212 KB ok
39 Correct 1 ms 212 KB ok
40 Correct 1 ms 212 KB ok
41 Correct 1 ms 212 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB ok
2 Correct 0 ms 212 KB ok
3 Correct 1 ms 240 KB ok
4 Correct 0 ms 212 KB ok
5 Correct 0 ms 212 KB ok
6 Correct 0 ms 232 KB ok
7 Correct 1 ms 212 KB ok
8 Correct 0 ms 212 KB ok
9 Correct 0 ms 212 KB ok
10 Correct 0 ms 212 KB ok
11 Correct 1 ms 212 KB ok
12 Correct 0 ms 212 KB ok
13 Correct 1 ms 212 KB ok
14 Correct 1 ms 212 KB ok
15 Correct 1 ms 212 KB ok
16 Correct 0 ms 212 KB ok
17 Correct 1 ms 212 KB ok
18 Correct 1 ms 212 KB ok
19 Correct 0 ms 212 KB ok
20 Correct 0 ms 212 KB ok
21 Correct 0 ms 212 KB ok
22 Correct 1 ms 212 KB ok
23 Correct 1 ms 212 KB ok
24 Correct 0 ms 212 KB ok
25 Correct 0 ms 212 KB ok
26 Correct 0 ms 212 KB ok
27 Correct 1 ms 212 KB ok
28 Correct 1 ms 212 KB ok
29 Correct 1 ms 212 KB ok
30 Correct 1 ms 212 KB ok
31 Correct 1 ms 212 KB ok
32 Correct 1 ms 212 KB ok
33 Correct 1 ms 256 KB ok
34 Correct 1 ms 212 KB ok
35 Correct 0 ms 212 KB ok
36 Correct 0 ms 212 KB ok
37 Correct 1 ms 212 KB ok
38 Correct 0 ms 212 KB ok
39 Correct 1 ms 212 KB ok
40 Correct 1 ms 212 KB ok
41 Correct 1 ms 212 KB ok
42 Correct 72 ms 6376 KB ok
43 Correct 78 ms 7120 KB ok
44 Correct 32 ms 4052 KB ok
45 Correct 34 ms 3732 KB ok
46 Correct 75 ms 5456 KB ok
47 Correct 16 ms 3284 KB ok
48 Correct 25 ms 3284 KB ok
49 Correct 18 ms 3220 KB ok
50 Correct 33 ms 3216 KB ok
51 Correct 30 ms 4308 KB ok
52 Correct 19 ms 3284 KB ok
53 Correct 19 ms 3224 KB ok
54 Correct 19 ms 3284 KB ok
55 Correct 20 ms 3284 KB ok
56 Correct 17 ms 3304 KB ok
57 Correct 75 ms 7204 KB ok
58 Correct 85 ms 7760 KB ok
59 Correct 88 ms 8280 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB ok
2 Correct 0 ms 212 KB ok
3 Correct 1 ms 240 KB ok
4 Correct 0 ms 212 KB ok
5 Correct 0 ms 212 KB ok
6 Correct 1 ms 256 KB ok
7 Correct 0 ms 212 KB ok
8 Correct 1 ms 340 KB ok
9 Correct 23 ms 3284 KB ok
10 Correct 385 ms 47444 KB ok
11 Correct 0 ms 232 KB ok
12 Correct 1 ms 212 KB ok
13 Correct 0 ms 212 KB ok
14 Correct 0 ms 212 KB ok
15 Correct 0 ms 212 KB ok
16 Correct 1 ms 212 KB ok
17 Correct 0 ms 212 KB ok
18 Correct 1 ms 212 KB ok
19 Correct 1 ms 212 KB ok
20 Correct 1 ms 212 KB ok
21 Correct 0 ms 212 KB ok
22 Correct 1 ms 212 KB ok
23 Correct 1 ms 212 KB ok
24 Correct 0 ms 212 KB ok
25 Correct 0 ms 212 KB ok
26 Correct 0 ms 212 KB ok
27 Correct 1 ms 212 KB ok
28 Correct 1 ms 212 KB ok
29 Correct 0 ms 212 KB ok
30 Correct 0 ms 212 KB ok
31 Correct 0 ms 212 KB ok
32 Correct 1 ms 212 KB ok
33 Correct 1 ms 212 KB ok
34 Correct 1 ms 212 KB ok
35 Correct 1 ms 212 KB ok
36 Correct 1 ms 212 KB ok
37 Correct 1 ms 212 KB ok
38 Correct 1 ms 256 KB ok
39 Correct 1 ms 212 KB ok
40 Correct 0 ms 212 KB ok
41 Correct 0 ms 212 KB ok
42 Correct 1 ms 212 KB ok
43 Correct 0 ms 212 KB ok
44 Correct 1 ms 212 KB ok
45 Correct 1 ms 212 KB ok
46 Correct 1 ms 212 KB ok
47 Correct 72 ms 6376 KB ok
48 Correct 78 ms 7120 KB ok
49 Correct 32 ms 4052 KB ok
50 Correct 34 ms 3732 KB ok
51 Correct 75 ms 5456 KB ok
52 Correct 16 ms 3284 KB ok
53 Correct 25 ms 3284 KB ok
54 Correct 18 ms 3220 KB ok
55 Correct 33 ms 3216 KB ok
56 Correct 30 ms 4308 KB ok
57 Correct 19 ms 3284 KB ok
58 Correct 19 ms 3224 KB ok
59 Correct 19 ms 3284 KB ok
60 Correct 20 ms 3284 KB ok
61 Correct 17 ms 3304 KB ok
62 Correct 75 ms 7204 KB ok
63 Correct 85 ms 7760 KB ok
64 Correct 88 ms 8280 KB ok
65 Correct 1286 ms 98276 KB ok
66 Correct 1057 ms 94608 KB ok
67 Correct 612 ms 68396 KB ok
68 Correct 353 ms 50000 KB ok
69 Correct 649 ms 61592 KB ok
70 Correct 751 ms 71216 KB ok
71 Correct 330 ms 48916 KB ok
72 Correct 251 ms 47500 KB ok
73 Correct 450 ms 47600 KB ok
74 Correct 304 ms 47632 KB ok
75 Correct 288 ms 47628 KB ok
76 Correct 513 ms 47596 KB ok
77 Correct 518 ms 47588 KB ok
78 Correct 515 ms 57616 KB ok
79 Correct 390 ms 51868 KB ok
80 Correct 392 ms 50464 KB ok
81 Correct 373 ms 50584 KB ok
82 Correct 430 ms 54408 KB ok
83 Correct 631 ms 66448 KB ok
84 Correct 324 ms 47632 KB ok
85 Correct 375 ms 47584 KB ok
86 Correct 333 ms 47764 KB ok
87 Correct 331 ms 48652 KB ok
88 Correct 306 ms 47504 KB ok
89 Correct 347 ms 47504 KB ok
90 Correct 322 ms 47632 KB ok
91 Correct 274 ms 47632 KB ok
92 Correct 622 ms 59252 KB ok
93 Correct 806 ms 61332 KB ok
94 Correct 466 ms 51996 KB ok
95 Correct 400 ms 49932 KB ok
96 Correct 389 ms 49164 KB ok
97 Correct 348 ms 48708 KB ok
98 Correct 371 ms 48116 KB ok
99 Correct 1260 ms 113024 KB ok
100 Correct 1360 ms 110516 KB ok
101 Correct 1319 ms 104380 KB ok
102 Correct 1440 ms 110540 KB ok
103 Correct 2289 ms 121156 KB ok
104 Correct 1959 ms 125032 KB ok
105 Correct 1846 ms 128056 KB ok
106 Correct 1658 ms 131216 KB ok
107 Correct 1972 ms 130520 KB ok
108 Correct 626 ms 52732 KB ok
109 Correct 545 ms 52684 KB ok