Submission #840713

# Submission time Handle Problem Language Result Execution time Memory
840713 2023-08-31T16:09:45 Z danikoynov Soccer Stadium (IOI23_soccer) C++17
48 / 100
4500 ms 501936 KB
#include "soccer.h"
#include <bits/stdc++.h>

using namespace std;

const int maxn = 510;
int a[maxn][maxn], bef[maxn][maxn], aft[maxn][maxn];
int dp[maxn][maxn][maxn], pref[maxn][maxn];

int biggest_stadium(int N, std::vector<std::vector<int>> F)
{
    for (int i = 0; i < N; i ++)
        for (int j = 0; j < N; j ++)
    {
        a[i + 1][j + 1] = F[i][j];
    }

    for (int j = 1; j <= N; j ++)
    {
        for (int i = 1; i <= N; i ++)
            pref[i][j] = pref[i - 1][j] + a[i][j];
    }
    for (int i = 1; i <= N; i ++)
    {
        for (int j = 1; j <= N; j ++)
        {
            if (a[i][j] == 1)
                bef[i][j] = j;
            else
                bef[i][j] = bef[i][j - 1];
        }

        aft[i][N + 1] = N + 1;
        for (int j = N; j > 0; j --)
        {
            if (a[i][j] == 1)
                aft[i][j] = j;
            else
                aft[i][j] = aft[i][j + 1];
        }
    }

    int ans = 0;
    for (int col = 1; col <= N; col ++)
            ///int col = 5;
    {


        for (int len = 1; len <= N; len ++)
        {
            for (int i = 1; i <= N - len + 1; i ++)
            {
                int j = i + len - 1;


                bool done = false;
                if (pref[j][col] - pref[i - 1][col] > 0)
                    continue;
                int left_width = N, right_width = N;
                for (int k = i; k <= j; k ++)
                {
                    if (a[k][col] == 1)
                    {
                        done = true;
                        break;
                    }

                    left_width = min(left_width, col - bef[k][col]);
                    right_width = min(right_width, aft[k][col] - col);
                }

                if (done)
                    continue;
                    int base_area = (j - i + 1) * (left_width + right_width - 1);
                dp[col][i][j] = base_area;

                if (left_width != col)
                {
                    vector < int > split;
                    split.push_back(i - 1);
                    for (int k = i; k <= j; k ++)
                    {
                        if (bef[k][col] == col - left_width)
                            split.push_back(k);
                    }
                    split.push_back(j + 1);

                    for (int d = 1; d < (int)(split.size()); d ++)
                    {
                        ///cout << "check " << split[d - 1] + 1 << " " << split[d] - 1 << endl;
                        int rem_area = (split[d] - split[d - 1] - 1) * (left_width + right_width - 1);
                        dp[col][i][j] = max(dp[col][i][j], dp[col][split[d - 1] + 1][split[d] - 1] - rem_area + base_area);
                    }
                }

                if (right_width != N + 1 - col)
                {
                    vector < int > split;
                                        split.push_back(i - 1);
                    for (int k = i; k <= j; k ++)
                    {
                        if (aft[k][col] == col + right_width)
                            split.push_back(k);
                    }
                    split.push_back(j + 1);

                    for (int d = 1; d < (int)(split.size()); d ++)
                    {
                        int rem_area = (split[d] - split[d - 1] - 1) * (left_width + right_width - 1);
                        dp[col][i][j] = max(dp[col][i][j], dp[col][split[d - 1] + 1][split[d] - 1] - rem_area + base_area);
                    }
                }
                ans = max(ans, dp[col][i][j]);
                ///cout << i << " : " << j << " = " << dp[col][i][j] << endl;
            }

        }
    }
    return ans;
}

Compilation message

soccer.cpp: In function 'int biggest_stadium(int, std::vector<std::vector<int> >)':
soccer.cpp:72:17: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   72 |                 if (done)
      |                 ^~
soccer.cpp:74:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   74 |                     int base_area = (j - i + 1) * (left_width + right_width - 1);
      |                     ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB ok
2 Correct 0 ms 340 KB ok
3 Correct 1 ms 488 KB ok
4 Correct 0 ms 596 KB ok
5 Correct 0 ms 212 KB ok
6 Correct 0 ms 340 KB ok
7 Correct 93 ms 21448 KB ok
8 Execution timed out 4538 ms 76424 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB ok
2 Correct 0 ms 340 KB ok
3 Correct 1 ms 340 KB ok
4 Correct 0 ms 340 KB ok
5 Correct 1 ms 340 KB ok
6 Correct 0 ms 340 KB ok
7 Correct 0 ms 340 KB ok
8 Correct 1 ms 340 KB ok
9 Correct 0 ms 340 KB ok
10 Correct 0 ms 340 KB ok
11 Correct 1 ms 340 KB ok
12 Correct 0 ms 340 KB ok
13 Correct 1 ms 340 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB ok
2 Correct 0 ms 340 KB ok
3 Correct 0 ms 340 KB ok
4 Correct 1 ms 340 KB ok
5 Correct 0 ms 340 KB ok
6 Correct 1 ms 340 KB ok
7 Correct 0 ms 340 KB ok
8 Correct 0 ms 340 KB ok
9 Correct 1 ms 340 KB ok
10 Correct 0 ms 340 KB ok
11 Correct 0 ms 340 KB ok
12 Correct 1 ms 340 KB ok
13 Correct 0 ms 340 KB ok
14 Correct 1 ms 340 KB ok
15 Correct 1 ms 468 KB ok
16 Correct 1 ms 468 KB ok
17 Correct 0 ms 468 KB ok
18 Correct 1 ms 468 KB ok
19 Correct 1 ms 340 KB ok
20 Correct 0 ms 340 KB ok
21 Correct 0 ms 340 KB ok
22 Correct 0 ms 340 KB ok
23 Correct 0 ms 340 KB ok
24 Correct 1 ms 360 KB ok
25 Correct 1 ms 340 KB ok
26 Correct 0 ms 468 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB ok
2 Correct 0 ms 340 KB ok
3 Correct 0 ms 340 KB ok
4 Correct 1 ms 488 KB ok
5 Correct 0 ms 596 KB ok
6 Correct 1 ms 340 KB ok
7 Correct 0 ms 340 KB ok
8 Correct 1 ms 340 KB ok
9 Correct 0 ms 340 KB ok
10 Correct 0 ms 340 KB ok
11 Correct 1 ms 340 KB ok
12 Correct 0 ms 340 KB ok
13 Correct 0 ms 340 KB ok
14 Correct 1 ms 340 KB ok
15 Correct 0 ms 340 KB ok
16 Correct 1 ms 340 KB ok
17 Correct 1 ms 468 KB ok
18 Correct 1 ms 468 KB ok
19 Correct 0 ms 468 KB ok
20 Correct 1 ms 468 KB ok
21 Correct 1 ms 340 KB ok
22 Correct 0 ms 340 KB ok
23 Correct 0 ms 340 KB ok
24 Correct 0 ms 340 KB ok
25 Correct 0 ms 340 KB ok
26 Correct 1 ms 360 KB ok
27 Correct 1 ms 340 KB ok
28 Correct 0 ms 468 KB ok
29 Correct 1 ms 340 KB ok
30 Correct 2 ms 2388 KB ok
31 Correct 3 ms 2388 KB ok
32 Correct 2 ms 1876 KB ok
33 Correct 1 ms 980 KB ok
34 Correct 1 ms 852 KB ok
35 Correct 1 ms 1108 KB ok
36 Correct 1 ms 852 KB ok
37 Correct 1 ms 852 KB ok
38 Correct 1 ms 980 KB ok
39 Correct 1 ms 980 KB ok
40 Correct 1 ms 1876 KB ok
41 Correct 3 ms 2516 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB ok
2 Correct 0 ms 340 KB ok
3 Correct 0 ms 340 KB ok
4 Correct 1 ms 488 KB ok
5 Correct 0 ms 596 KB ok
6 Correct 1 ms 340 KB ok
7 Correct 0 ms 340 KB ok
8 Correct 1 ms 340 KB ok
9 Correct 0 ms 340 KB ok
10 Correct 0 ms 340 KB ok
11 Correct 1 ms 340 KB ok
12 Correct 0 ms 340 KB ok
13 Correct 0 ms 340 KB ok
14 Correct 1 ms 340 KB ok
15 Correct 0 ms 340 KB ok
16 Correct 1 ms 340 KB ok
17 Correct 1 ms 468 KB ok
18 Correct 1 ms 468 KB ok
19 Correct 0 ms 468 KB ok
20 Correct 1 ms 468 KB ok
21 Correct 1 ms 340 KB ok
22 Correct 0 ms 340 KB ok
23 Correct 0 ms 340 KB ok
24 Correct 0 ms 340 KB ok
25 Correct 0 ms 340 KB ok
26 Correct 1 ms 360 KB ok
27 Correct 1 ms 340 KB ok
28 Correct 0 ms 468 KB ok
29 Correct 1 ms 340 KB ok
30 Correct 2 ms 2388 KB ok
31 Correct 3 ms 2388 KB ok
32 Correct 2 ms 1876 KB ok
33 Correct 1 ms 980 KB ok
34 Correct 1 ms 852 KB ok
35 Correct 1 ms 1108 KB ok
36 Correct 1 ms 852 KB ok
37 Correct 1 ms 852 KB ok
38 Correct 1 ms 980 KB ok
39 Correct 1 ms 980 KB ok
40 Correct 1 ms 1876 KB ok
41 Correct 3 ms 2516 KB ok
42 Correct 870 ms 501936 KB ok
43 Correct 551 ms 486696 KB ok
44 Execution timed out 4531 ms 179116 KB Time limit exceeded
45 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB ok
2 Correct 0 ms 340 KB ok
3 Correct 0 ms 340 KB ok
4 Correct 1 ms 488 KB ok
5 Correct 0 ms 596 KB ok
6 Correct 0 ms 212 KB ok
7 Correct 0 ms 340 KB ok
8 Correct 93 ms 21448 KB ok
9 Execution timed out 4538 ms 76424 KB Time limit exceeded
10 Halted 0 ms 0 KB -