답안 #963760

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963760 2024-04-15T15:40:12 Z tutis 축구 경기장 (IOI23_soccer) C++17
70 / 100
4500 ms 137412 KB
//#include "soccer.h"
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int biggest_stadium(int N, std::vector<std::vector<int>> C) {
    vector<vector<int>> S(N);
    auto fS = [&](int x, int y) {
        if (x < 0 || y < 0) {
            return 0;
        }
        if (x >= N) {
            x = N - 1;
        }
        if (y >= N) {
            y = N - 1;
        }
        return S[x][y];
    };
    auto sm = [&](int x1, int x2, int y1, int y2) -> int {
        return fS(x2, y2) - fS(x1 - 1, y2) - fS(x2, y1 - 1) + fS(x1 - 1, y1 - 1);
    };
    for (int i = 0; i < N; i++) {
        S[i] = vector<int>(N);
        for (int j = 0; j < N; j++) {
            S[i][j] = C[i][j];
            S[i][j] += fS(i - 1, j) + fS(i, j - 1) - fS(i - 1, j - 1);
        }
    }
    int best = 0;
    vector<pair<pair<int, int>, pair<int, int>>> V;
    function<void(int, int, int, int)> dfs = [&](int x1, int x2, int y1, int y2) -> void {
        if (y1 > y2) {
            return;
        }
        if (x2 != N - 1 && sm(x2 + 1, x2 + 1, y1, y2) == 0) {
            return;
        }
        if (x1 == 0) {
            V.push_back({{x1, x2},
                         {y1, y2}});
            return;
        }
        if (sm(x1 - 1, x1 - 1, y1, y2) != 0) {
            V.push_back({{x1, x2},
                         {y1, y2}});
        }
        int lst = y1 - 1;
        for (int y = y1; y <= y2 + 1; y++) {
            if (y == y2 + 1 || C[x1 - 1][y] == 1) {
                dfs(x1 - 1, x2, lst + 1, y - 1);
                lst = y;
            }
        }
    };
    for (int x = 0; x < N; x++) {
        int lst = -1;
        for (int y = 0; y <= N; y++) {
            if (y == N || C[x][y] == 1) {
                if (lst + 1 > y - 1) {
                    lst = y;
                    continue;
                }
                if (x != N - 1 && sm(x + 1, x + 1, lst + 1, y - 1) == 0) {
                    lst = y;
                    continue;
                }
                dfs(x, x, lst + 1, y - 1);
                lst = y;
            }
        }
    }
    sort(V.begin(), V.end(),
         [&](pair<pair<int, int>, pair<int, int>> a, pair<pair<int, int>, pair<int, int>> b) {
             return a.second.second - a.second.first > b.second.second - b.second.first;
         });
    map<pair<pair<int, int>, pair<int, int>>, int> M;
    auto check = [&](pair<pair<int, int>, pair<int, int>> i, int area) {
        auto [xp, yp] = i;
        auto [x0, x1] = xp;
        auto [y0, y1] = yp;
        if (y0 > y1) {
            return;
        }
        int lo = 0;
        int hi = x0;
        while (lo < hi) {
            int m = (lo + hi) / 2;
            if (sm(m, x0 - 1, y0, y1) == 0) {
                hi = m;
            } else {
                lo = m + 1;
            }
        }
        area += (y1 - y0 + 1) * (x0 - lo);
        x0 = lo;
        lo = x1;
        hi = N - 1;
        while (lo < hi) {
            int m = (lo + hi + 1) / 2;
            if (sm(x1 + 1, m, y0, y1) == 0) {
                lo = m;
            } else {
                hi = m - 1;
            }
        }
 
        area += (y1 - y0 + 1) * (lo - x1);
        x1 = lo;
        M[{{x0, x1},
           {y0, y1}}] = max(M[{{x0, x1},
                               {y0, y1}}],
                            area);
    };
    auto expL = [&](pair<pair<int, int>, pair<int, int>> i, int area) {
        auto [xp, yp] = i;
        auto [x0, x1] = xp;
        auto [y0, y1] = yp;
        if (y0 > y1) {
            return;
        }
        int lst = y0 - 1;
        for (int y = y0; y <= y1 + 1; y++) {
            if (y == y1 + 1 || C[x0 - 1][y] == 1) {
                check({{x0 - 1,  x1},
                       {lst + 1, y - 1}}, area + (y - 1) - (lst + 1) + 1);
                lst = y;
            }
        }
    };
    auto expR = [&](pair<pair<int, int>, pair<int, int>> i, int area) {
        auto [xp, yp] = i;
        auto [x0, x1] = xp;
        auto [y0, y1] = yp;
        if (y0 > y1) {
            return;
        }
        int lst = y0 - 1;
        for (int y = y0; y <= y1 + 1; y++) {
            if (y == y1 + 1 || C[x1 + 1][y] == 1) {
                check({{x0,      x1 + 1},
                       {lst + 1, y - 1}}, area + (y - 1) - (lst + 1) + 1);
                lst = y;
            }
        }
    };
    for (auto i: V) {
        auto [xp, yp] = i;
        auto [x0, x1] = xp;
        auto [y0, y1] = yp;
        int dp = (x1 - x0 + 1) * (y1 - y0 + 1);
        if (M.count(i)) {
            dp = M[i];
        } else {
            M[i] = dp;
        }
        int ans = dp;
        best = max(best, ans);
        if (x0 != 0) {
            expL(i, ans);
        }
        if (x1 != N - 1) {
            expR(i, ans);
        }
    }
 
    return best;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB ok
2 Correct 1 ms 348 KB ok
3 Correct 0 ms 348 KB ok
4 Correct 1 ms 348 KB ok
5 Correct 1 ms 348 KB ok
6 Correct 0 ms 432 KB ok
7 Correct 1 ms 348 KB ok
8 Correct 20 ms 3976 KB ok
9 Correct 291 ms 51792 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB ok
2 Correct 1 ms 348 KB ok
3 Correct 0 ms 344 KB ok
4 Correct 0 ms 344 KB ok
5 Correct 1 ms 504 KB ok
6 Correct 1 ms 348 KB ok
7 Correct 0 ms 348 KB ok
8 Correct 1 ms 348 KB ok
9 Correct 0 ms 348 KB ok
10 Correct 1 ms 348 KB ok
11 Correct 0 ms 348 KB ok
12 Correct 0 ms 392 KB ok
13 Correct 0 ms 348 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB ok
2 Correct 0 ms 348 KB ok
3 Correct 1 ms 348 KB ok
4 Correct 0 ms 344 KB ok
5 Correct 0 ms 344 KB ok
6 Correct 1 ms 504 KB ok
7 Correct 1 ms 348 KB ok
8 Correct 0 ms 348 KB ok
9 Correct 1 ms 348 KB ok
10 Correct 0 ms 348 KB ok
11 Correct 1 ms 348 KB ok
12 Correct 0 ms 348 KB ok
13 Correct 0 ms 392 KB ok
14 Correct 0 ms 348 KB ok
15 Correct 1 ms 348 KB ok
16 Correct 1 ms 436 KB ok
17 Correct 0 ms 348 KB ok
18 Correct 1 ms 348 KB ok
19 Correct 0 ms 348 KB ok
20 Correct 0 ms 348 KB ok
21 Correct 0 ms 424 KB ok
22 Correct 1 ms 348 KB ok
23 Correct 0 ms 432 KB ok
24 Correct 1 ms 348 KB ok
25 Correct 0 ms 348 KB ok
26 Correct 0 ms 344 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB ok
2 Correct 0 ms 348 KB ok
3 Correct 1 ms 348 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 1 ms 348 KB ok
6 Correct 0 ms 344 KB ok
7 Correct 0 ms 344 KB ok
8 Correct 1 ms 504 KB ok
9 Correct 1 ms 348 KB ok
10 Correct 0 ms 348 KB ok
11 Correct 1 ms 348 KB ok
12 Correct 0 ms 348 KB ok
13 Correct 1 ms 348 KB ok
14 Correct 0 ms 348 KB ok
15 Correct 0 ms 392 KB ok
16 Correct 0 ms 348 KB ok
17 Correct 1 ms 348 KB ok
18 Correct 1 ms 436 KB ok
19 Correct 0 ms 348 KB ok
20 Correct 1 ms 348 KB ok
21 Correct 0 ms 348 KB ok
22 Correct 0 ms 348 KB ok
23 Correct 0 ms 424 KB ok
24 Correct 1 ms 348 KB ok
25 Correct 0 ms 432 KB ok
26 Correct 1 ms 348 KB ok
27 Correct 0 ms 348 KB ok
28 Correct 0 ms 344 KB ok
29 Correct 1 ms 348 KB ok
30 Correct 1 ms 348 KB ok
31 Correct 1 ms 432 KB ok
32 Correct 1 ms 344 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 0 ms 348 KB ok
38 Correct 1 ms 500 KB ok
39 Correct 1 ms 348 KB ok
40 Correct 1 ms 344 KB ok
41 Correct 1 ms 348 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB ok
2 Correct 0 ms 348 KB ok
3 Correct 1 ms 348 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 1 ms 348 KB ok
6 Correct 0 ms 344 KB ok
7 Correct 0 ms 344 KB ok
8 Correct 1 ms 504 KB ok
9 Correct 1 ms 348 KB ok
10 Correct 0 ms 348 KB ok
11 Correct 1 ms 348 KB ok
12 Correct 0 ms 348 KB ok
13 Correct 1 ms 348 KB ok
14 Correct 0 ms 348 KB ok
15 Correct 0 ms 392 KB ok
16 Correct 0 ms 348 KB ok
17 Correct 1 ms 348 KB ok
18 Correct 1 ms 436 KB ok
19 Correct 0 ms 348 KB ok
20 Correct 1 ms 348 KB ok
21 Correct 0 ms 348 KB ok
22 Correct 0 ms 348 KB ok
23 Correct 0 ms 424 KB ok
24 Correct 1 ms 348 KB ok
25 Correct 0 ms 432 KB ok
26 Correct 1 ms 348 KB ok
27 Correct 0 ms 348 KB ok
28 Correct 0 ms 344 KB ok
29 Correct 1 ms 348 KB ok
30 Correct 1 ms 348 KB ok
31 Correct 1 ms 432 KB ok
32 Correct 1 ms 344 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 0 ms 348 KB ok
38 Correct 1 ms 500 KB ok
39 Correct 1 ms 348 KB ok
40 Correct 1 ms 344 KB ok
41 Correct 1 ms 348 KB ok
42 Correct 123 ms 7652 KB ok
43 Correct 127 ms 8652 KB ok
44 Correct 57 ms 4832 KB ok
45 Correct 45 ms 4568 KB ok
46 Correct 102 ms 6604 KB ok
47 Correct 19 ms 3936 KB ok
48 Correct 26 ms 3968 KB ok
49 Correct 32 ms 3940 KB ok
50 Correct 48 ms 3968 KB ok
51 Correct 36 ms 5340 KB ok
52 Correct 19 ms 3932 KB ok
53 Correct 18 ms 3932 KB ok
54 Correct 20 ms 3976 KB ok
55 Correct 22 ms 3932 KB ok
56 Correct 25 ms 3856 KB ok
57 Correct 147 ms 8916 KB ok
58 Correct 161 ms 9412 KB ok
59 Correct 175 ms 10428 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB ok
2 Correct 0 ms 348 KB ok
3 Correct 1 ms 348 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 1 ms 348 KB ok
6 Correct 1 ms 348 KB ok
7 Correct 0 ms 432 KB ok
8 Correct 1 ms 348 KB ok
9 Correct 20 ms 3976 KB ok
10 Correct 291 ms 51792 KB ok
11 Correct 0 ms 344 KB ok
12 Correct 0 ms 344 KB ok
13 Correct 1 ms 504 KB ok
14 Correct 1 ms 348 KB ok
15 Correct 0 ms 348 KB ok
16 Correct 1 ms 348 KB ok
17 Correct 0 ms 348 KB ok
18 Correct 1 ms 348 KB ok
19 Correct 0 ms 348 KB ok
20 Correct 0 ms 392 KB ok
21 Correct 0 ms 348 KB ok
22 Correct 1 ms 348 KB ok
23 Correct 1 ms 436 KB ok
24 Correct 0 ms 348 KB ok
25 Correct 1 ms 348 KB ok
26 Correct 0 ms 348 KB ok
27 Correct 0 ms 348 KB ok
28 Correct 0 ms 424 KB ok
29 Correct 1 ms 348 KB ok
30 Correct 0 ms 432 KB ok
31 Correct 1 ms 348 KB ok
32 Correct 0 ms 348 KB ok
33 Correct 0 ms 344 KB ok
34 Correct 1 ms 348 KB ok
35 Correct 1 ms 348 KB ok
36 Correct 1 ms 432 KB ok
37 Correct 1 ms 344 KB ok
38 Correct 0 ms 348 KB ok
39 Correct 0 ms 348 KB ok
40 Correct 1 ms 348 KB ok
41 Correct 1 ms 348 KB ok
42 Correct 0 ms 348 KB ok
43 Correct 1 ms 500 KB ok
44 Correct 1 ms 348 KB ok
45 Correct 1 ms 344 KB ok
46 Correct 1 ms 348 KB ok
47 Correct 123 ms 7652 KB ok
48 Correct 127 ms 8652 KB ok
49 Correct 57 ms 4832 KB ok
50 Correct 45 ms 4568 KB ok
51 Correct 102 ms 6604 KB ok
52 Correct 19 ms 3936 KB ok
53 Correct 26 ms 3968 KB ok
54 Correct 32 ms 3940 KB ok
55 Correct 48 ms 3968 KB ok
56 Correct 36 ms 5340 KB ok
57 Correct 19 ms 3932 KB ok
58 Correct 18 ms 3932 KB ok
59 Correct 20 ms 3976 KB ok
60 Correct 22 ms 3932 KB ok
61 Correct 25 ms 3856 KB ok
62 Correct 147 ms 8916 KB ok
63 Correct 161 ms 9412 KB ok
64 Correct 175 ms 10428 KB ok
65 Correct 4323 ms 116744 KB ok
66 Correct 949 ms 111272 KB ok
67 Correct 453 ms 78572 KB ok
68 Correct 729 ms 55004 KB ok
69 Correct 1915 ms 69376 KB ok
70 Correct 2783 ms 82812 KB ok
71 Correct 548 ms 53680 KB ok
72 Correct 304 ms 52004 KB ok
73 Correct 710 ms 51880 KB ok
74 Correct 744 ms 51992 KB ok
75 Correct 744 ms 52048 KB ok
76 Correct 914 ms 52368 KB ok
77 Correct 940 ms 55956 KB ok
78 Correct 712 ms 68532 KB ok
79 Correct 418 ms 60796 KB ok
80 Correct 387 ms 59144 KB ok
81 Correct 399 ms 59260 KB ok
82 Correct 655 ms 64084 KB ok
83 Correct 935 ms 80096 KB ok
84 Correct 320 ms 55564 KB ok
85 Correct 286 ms 55612 KB ok
86 Correct 333 ms 55632 KB ok
87 Correct 389 ms 56844 KB ok
88 Correct 553 ms 55436 KB ok
89 Correct 313 ms 55564 KB ok
90 Correct 366 ms 55812 KB ok
91 Correct 357 ms 55604 KB ok
92 Correct 540 ms 70584 KB ok
93 Correct 547 ms 72784 KB ok
94 Correct 377 ms 60928 KB ok
95 Correct 341 ms 58312 KB ok
96 Correct 325 ms 57284 KB ok
97 Correct 310 ms 56704 KB ok
98 Correct 297 ms 56108 KB ok
99 Correct 3546 ms 137412 KB ok
100 Execution timed out 4567 ms 102956 KB Time limit exceeded
101 Halted 0 ms 0 KB -