Submission #1011988

# Submission time Handle Problem Language Result Execution time Memory
1011988 2024-07-01T13:30:59 Z mdn2002 Soccer Stadium (IOI23_soccer) C++17
100 / 100
4269 ms 400416 KB
#include "soccer.h"
#include<bits/stdc++.h>
using namespace std;
int dp[8000006];
int biggest_stadium(int N, vector<vector<int>> F) {
    int n = N;
    vector<vector<int>> a = F, next(n, vector<int>(n)), sum(n, vector<int>(n));
    map<vector<int>, int> mp;
    vector<vector<int>> v(n);
    set<pair<int, vector<int>>> vv;

    function<int(int, int, int, int)> summ = [&] (int l, int r, int x, int y) {
        long long ans = sum[y][r];
        if (x - 1 >= 0) ans -= sum[x - 1][r];
        if (l - 1 >= 0) ans -= sum[y][l - 1];
        if (x - 1 >= 0 && l - 1 >= 0) ans += sum[x - 1][l - 1];
        return ans;
    };

    int cnt = 0;

    for (int i = 0; i < n; i ++) {
        for (int j = 0; j < n; j ++) {
            sum[i][j] += a[i][j];
            if (j) sum[i][j] += sum[i][j - 1];
            if (a[i][j] == 0) v[i].push_back(j);
        }
        v[i].push_back(n + 1);
    }
    for (int i = 1; i < n; i ++) {
        for (int j = 0; j < n; j ++) sum[i][j] += sum[i - 1][j];
    }
    for (int i = 0; i < n; i ++) {
        if (a[i][n - 1] == 0) next[i][n - 1] = n - 1;
        else next[i][n - 1] = n - 2;
        for (int j = n - 2; j >= 0; j --) {
            if (a[i][j]) next[i][j] = j - 1;
            else next[i][j] = next[i][j + 1];
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i ++) {
        for (int j = 0; j < n; j ++) {
            if (a[i][j]) continue;
            int ll = i, rr = n, mid, x, y;
            while (ll < rr) {
                mid = (ll + rr) / 2;
                if (summ(j, next[i][j], i, mid) == 0) ll = mid + 1;
                else rr = mid;
            }
            ll --;
            y = ll;

            ll = 0, rr = i;
            while (ll < rr) {
                mid = (ll + rr) / 2;
                if (summ(j, next[i][j], mid, i) == 0) rr = mid;
                else ll = mid + 1;
            }
            x = ll;
            vector<int> vvv = {j, next[i][j], x, y};
            if (mp[vvv] == 0) {
                vv.insert({-(next[i][j] - j), vvv});
                mp[vvv] = ++ cnt;
            }
            j = next[i][j];
        }
    }

    for (auto xxxx : vv) {
        auto [zzzz, xx] = xxxx;
        if (mp.count(xx) == 0) mp[xx] = ++ cnt;
        int id = mp[xx];
        dp[id] = max(dp[id], (xx[1] - xx[0] + 1) * (xx[3] - xx[2] + 1));
        ans = max(ans, dp[id]);

        int l = xx[0], r = xx[1], x = xx[2], y = xx[3];

        if (x - 1 >= 0) {
            for (int j = l; j <= r; j ++) {
                int z = min(r, next[x - 1][j]);
                if (a[x - 1][j] == 0) {

                    int ll = y, rr = n, mid, nx, ny;
                    while (ll < rr) {
                        mid = (ll + rr) / 2;
                        if (summ(j, z, x, mid) == 0) ll = mid + 1;
                        else rr = mid;
                    }
                    ll --;
                    ny = ll;

                    ll = 0, rr = x;
                    while (ll < rr) {
                        mid = (ll + rr) / 2;
                        if (summ(j, z, mid, y) == 0) rr = mid;
                        else ll = mid + 1;
                    }
                    nx = ll;

                    vector<int> xxx = {j, z, nx, ny};
                    if (mp.count(xxx) == 0) {
                        mp[xxx] = ++ cnt;
                        vv.insert({-(z - j), xxx});
                    }
                    int idd = mp[xxx];
                    dp[idd] = max(dp[idd], dp[id] + (z - j + 1) * (x - nx + ny - y));
                }
                j = *upper_bound(v[x - 1].begin(), v[x - 1].end(), z) - 1;
            }
        }
        if (y + 1 < n) {
            for (int j = l; j <= r; j ++) {
                int z = min(r, next[y + 1][j]);
                if (a[y + 1][j] == 0) {
                    int ll = y, rr = n, mid, nx, ny;
                    while (ll < rr) {
                        mid = (ll + rr) / 2;
                        if (summ(j, z, x, mid) == 0) ll = mid + 1;
                        else rr = mid;
                    }
                    ll --;
                    ny = ll;

                    ll = 0, rr = x;
                    while (ll < rr) {
                        mid = (ll + rr) / 2;
                        if (summ(j, z, mid, y) == 0) rr = mid;
                        else ll = mid + 1;
                    }
                    nx = ll;

                    vector<int> xxx = {j, z, nx, ny};
                    if (mp.count(xxx) == 0) {
                        mp[xxx] = ++ cnt;
                        vv.insert({-(z - j), xxx});
                    }
                    int idd = mp[xxx];
                    dp[idd] = max(dp[idd], dp[id] + (z - j + 1) * (x - nx + ny - y));
                }
                j = *upper_bound(v[y + 1].begin(), v[y + 1].end(), z) - 1;
            }
        }
    }
    return ans;
}
/*
3
0 0 1
0 0 0
1 0 0
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB ok
2 Correct 0 ms 448 KB ok
3 Correct 0 ms 348 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 0 ms 348 KB ok
6 Correct 0 ms 348 KB ok
7 Correct 1 ms 604 KB ok
8 Correct 14 ms 6748 KB ok
9 Correct 206 ms 102996 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB ok
2 Correct 0 ms 448 KB ok
3 Correct 1 ms 344 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 0 ms 348 KB ok
6 Correct 0 ms 348 KB ok
7 Correct 0 ms 344 KB ok
8 Correct 0 ms 348 KB ok
9 Correct 0 ms 348 KB ok
10 Correct 0 ms 348 KB ok
11 Correct 0 ms 344 KB ok
12 Correct 0 ms 348 KB ok
13 Correct 0 ms 348 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB ok
2 Correct 0 ms 348 KB ok
3 Correct 0 ms 448 KB ok
4 Correct 1 ms 344 KB ok
5 Correct 0 ms 348 KB ok
6 Correct 0 ms 348 KB ok
7 Correct 0 ms 348 KB ok
8 Correct 0 ms 344 KB ok
9 Correct 0 ms 348 KB ok
10 Correct 0 ms 348 KB ok
11 Correct 0 ms 348 KB ok
12 Correct 0 ms 344 KB ok
13 Correct 0 ms 348 KB ok
14 Correct 0 ms 348 KB ok
15 Correct 0 ms 348 KB ok
16 Correct 0 ms 348 KB ok
17 Correct 0 ms 348 KB ok
18 Correct 0 ms 348 KB ok
19 Correct 0 ms 348 KB ok
20 Correct 0 ms 348 KB ok
21 Correct 0 ms 348 KB ok
22 Correct 0 ms 348 KB ok
23 Correct 0 ms 348 KB ok
24 Correct 0 ms 348 KB ok
25 Correct 0 ms 348 KB ok
26 Correct 0 ms 348 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB ok
2 Correct 0 ms 348 KB ok
3 Correct 0 ms 448 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 0 ms 348 KB ok
6 Correct 1 ms 344 KB ok
7 Correct 0 ms 348 KB ok
8 Correct 0 ms 348 KB ok
9 Correct 0 ms 348 KB ok
10 Correct 0 ms 344 KB ok
11 Correct 0 ms 348 KB ok
12 Correct 0 ms 348 KB ok
13 Correct 0 ms 348 KB ok
14 Correct 0 ms 344 KB ok
15 Correct 0 ms 348 KB ok
16 Correct 0 ms 348 KB ok
17 Correct 0 ms 348 KB ok
18 Correct 0 ms 348 KB ok
19 Correct 0 ms 348 KB ok
20 Correct 0 ms 348 KB ok
21 Correct 0 ms 348 KB ok
22 Correct 0 ms 348 KB ok
23 Correct 0 ms 348 KB ok
24 Correct 0 ms 348 KB ok
25 Correct 0 ms 348 KB ok
26 Correct 0 ms 348 KB ok
27 Correct 0 ms 348 KB ok
28 Correct 0 ms 348 KB ok
29 Correct 0 ms 348 KB ok
30 Correct 1 ms 348 KB ok
31 Correct 1 ms 348 KB ok
32 Correct 1 ms 348 KB ok
33 Correct 0 ms 348 KB ok
34 Correct 0 ms 348 KB ok
35 Correct 0 ms 348 KB ok
36 Correct 0 ms 348 KB ok
37 Correct 0 ms 348 KB ok
38 Correct 0 ms 348 KB ok
39 Correct 0 ms 348 KB ok
40 Correct 0 ms 348 KB ok
41 Correct 1 ms 348 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB ok
2 Correct 0 ms 348 KB ok
3 Correct 0 ms 448 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 0 ms 348 KB ok
6 Correct 1 ms 344 KB ok
7 Correct 0 ms 348 KB ok
8 Correct 0 ms 348 KB ok
9 Correct 0 ms 348 KB ok
10 Correct 0 ms 344 KB ok
11 Correct 0 ms 348 KB ok
12 Correct 0 ms 348 KB ok
13 Correct 0 ms 348 KB ok
14 Correct 0 ms 344 KB ok
15 Correct 0 ms 348 KB ok
16 Correct 0 ms 348 KB ok
17 Correct 0 ms 348 KB ok
18 Correct 0 ms 348 KB ok
19 Correct 0 ms 348 KB ok
20 Correct 0 ms 348 KB ok
21 Correct 0 ms 348 KB ok
22 Correct 0 ms 348 KB ok
23 Correct 0 ms 348 KB ok
24 Correct 0 ms 348 KB ok
25 Correct 0 ms 348 KB ok
26 Correct 0 ms 348 KB ok
27 Correct 0 ms 348 KB ok
28 Correct 0 ms 348 KB ok
29 Correct 0 ms 348 KB ok
30 Correct 1 ms 348 KB ok
31 Correct 1 ms 348 KB ok
32 Correct 1 ms 348 KB ok
33 Correct 0 ms 348 KB ok
34 Correct 0 ms 348 KB ok
35 Correct 0 ms 348 KB ok
36 Correct 0 ms 348 KB ok
37 Correct 0 ms 348 KB ok
38 Correct 0 ms 348 KB ok
39 Correct 0 ms 348 KB ok
40 Correct 0 ms 348 KB ok
41 Correct 1 ms 348 KB ok
42 Correct 127 ms 18004 KB ok
43 Correct 150 ms 20840 KB ok
44 Correct 51 ms 9808 KB ok
45 Correct 33 ms 8584 KB ok
46 Correct 103 ms 14424 KB ok
47 Correct 14 ms 6744 KB ok
48 Correct 15 ms 6492 KB ok
49 Correct 12 ms 6488 KB ok
50 Correct 36 ms 6760 KB ok
51 Correct 35 ms 10584 KB ok
52 Correct 13 ms 6236 KB ok
53 Correct 12 ms 6044 KB ok
54 Correct 14 ms 6232 KB ok
55 Correct 14 ms 6232 KB ok
56 Correct 13 ms 6236 KB ok
57 Correct 105 ms 21076 KB ok
58 Correct 110 ms 22840 KB ok
59 Correct 132 ms 24936 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB ok
2 Correct 0 ms 348 KB ok
3 Correct 0 ms 448 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 0 ms 348 KB ok
6 Correct 0 ms 348 KB ok
7 Correct 0 ms 348 KB ok
8 Correct 1 ms 604 KB ok
9 Correct 14 ms 6748 KB ok
10 Correct 206 ms 102996 KB ok
11 Correct 1 ms 344 KB ok
12 Correct 0 ms 348 KB ok
13 Correct 0 ms 348 KB ok
14 Correct 0 ms 348 KB ok
15 Correct 0 ms 344 KB ok
16 Correct 0 ms 348 KB ok
17 Correct 0 ms 348 KB ok
18 Correct 0 ms 348 KB ok
19 Correct 0 ms 344 KB ok
20 Correct 0 ms 348 KB ok
21 Correct 0 ms 348 KB ok
22 Correct 0 ms 348 KB ok
23 Correct 0 ms 348 KB ok
24 Correct 0 ms 348 KB ok
25 Correct 0 ms 348 KB ok
26 Correct 0 ms 348 KB ok
27 Correct 0 ms 348 KB ok
28 Correct 0 ms 348 KB ok
29 Correct 0 ms 348 KB ok
30 Correct 0 ms 348 KB ok
31 Correct 0 ms 348 KB ok
32 Correct 0 ms 348 KB ok
33 Correct 0 ms 348 KB ok
34 Correct 0 ms 348 KB ok
35 Correct 1 ms 348 KB ok
36 Correct 1 ms 348 KB ok
37 Correct 1 ms 348 KB ok
38 Correct 0 ms 348 KB ok
39 Correct 0 ms 348 KB ok
40 Correct 0 ms 348 KB ok
41 Correct 0 ms 348 KB ok
42 Correct 0 ms 348 KB ok
43 Correct 0 ms 348 KB ok
44 Correct 0 ms 348 KB ok
45 Correct 0 ms 348 KB ok
46 Correct 1 ms 348 KB ok
47 Correct 127 ms 18004 KB ok
48 Correct 150 ms 20840 KB ok
49 Correct 51 ms 9808 KB ok
50 Correct 33 ms 8584 KB ok
51 Correct 103 ms 14424 KB ok
52 Correct 14 ms 6744 KB ok
53 Correct 15 ms 6492 KB ok
54 Correct 12 ms 6488 KB ok
55 Correct 36 ms 6760 KB ok
56 Correct 35 ms 10584 KB ok
57 Correct 13 ms 6236 KB ok
58 Correct 12 ms 6044 KB ok
59 Correct 14 ms 6232 KB ok
60 Correct 14 ms 6232 KB ok
61 Correct 13 ms 6236 KB ok
62 Correct 105 ms 21076 KB ok
63 Correct 110 ms 22840 KB ok
64 Correct 132 ms 24936 KB ok
65 Correct 4269 ms 283680 KB ok
66 Correct 2529 ms 262736 KB ok
67 Correct 1073 ms 163412 KB ok
68 Correct 395 ms 111760 KB ok
69 Correct 1536 ms 152804 KB ok
70 Correct 2445 ms 187420 KB ok
71 Correct 317 ms 107880 KB ok
72 Correct 223 ms 103064 KB ok
73 Correct 233 ms 97620 KB ok
74 Correct 232 ms 97876 KB ok
75 Correct 221 ms 97876 KB ok
76 Correct 797 ms 99412 KB ok
77 Correct 769 ms 99356 KB ok
78 Correct 582 ms 138884 KB ok
79 Correct 390 ms 103248 KB ok
80 Correct 336 ms 98636 KB ok
81 Correct 379 ms 100180 KB ok
82 Correct 528 ms 117332 KB ok
83 Correct 1336 ms 158228 KB ok
84 Correct 229 ms 89428 KB ok
85 Correct 221 ms 88404 KB ok
86 Correct 218 ms 90452 KB ok
87 Correct 235 ms 94036 KB ok
88 Correct 235 ms 94112 KB ok
89 Correct 228 ms 102924 KB ok
90 Correct 232 ms 103060 KB ok
91 Correct 225 ms 101716 KB ok
92 Correct 802 ms 131408 KB ok
93 Correct 941 ms 138324 KB ok
94 Correct 412 ms 104532 KB ok
95 Correct 295 ms 97108 KB ok
96 Correct 284 ms 94740 KB ok
97 Correct 268 ms 93012 KB ok
98 Correct 239 ms 89936 KB ok
99 Correct 2628 ms 335688 KB ok
100 Correct 2344 ms 326928 KB ok
101 Correct 2158 ms 304944 KB ok
102 Correct 2529 ms 326956 KB ok
103 Correct 2742 ms 364872 KB ok
104 Correct 3128 ms 378632 KB ok
105 Correct 3239 ms 389368 KB ok
106 Correct 3326 ms 400416 KB ok
107 Correct 3304 ms 398164 KB ok
108 Correct 530 ms 120992 KB ok
109 Correct 524 ms 120916 KB ok