Submission #1038126

# Submission time Handle Problem Language Result Execution time Memory
1038126 2024-07-29T13:14:58 Z erray Soccer Stadium (IOI23_soccer) C++17
65.5 / 100
263 ms 35956 KB
#include "soccer.h"
#include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG 
  #include "/home/ioi/egoi2024/d2/debug.h"
#else 
  #define debug(...) void(37)
#endif

constexpr int mx_N = 30;
int dp[mx_N][mx_N][mx_N][mx_N];
void ckmax(int& x, int y) {
  x = max(x, y);
}

int biggest_stadium(int N, std::vector<std::vector<int>> F) {
  int tree_count = 0, one_tree_i, one_tree_j;
  for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) {
    if (F[i][j]) {
      tree_count++;
      one_tree_i = i, one_tree_j = j;
    }
  }
  if (tree_count <= 1) {
    if (tree_count == 0) return N * N;
    int i = one_tree_i;
    int j = one_tree_j;
    return N * N - min(i + 1, N - i) * min(j + 1, N - j);
  }
  if (N > mx_N) {
    vector<int> T(N, -1), B(N, -1), L(N, -1), R(N, -1);
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        if (F[i][j]) continue;
        if (T[j] == -1) T[j] = N - 1 - i;
        if (L[i] == -1) L[i] = N - 1 - j;
        B[j] = i;
        R[i] = j;
      }
    }
    int verc = 0, horc = 0;
    for (int i = 0; i < N; ++i) {
      if (L[i] != -1) {
        horc += 2 * (N - 1) - (L[i] + R[i]);
      } else {
        horc += N;
      }
      if (T[i] != -1) {
        verc += 2 * (N - 1) - (T[i] + B[i]);
      } else {
        verc += N;
      }
    }
    bool bad = (verc != tree_count || horc != tree_count);
    if (bad) {
      return 0;
    }
    debug(bad, L, R, B, T);
    int max_L = *max_element(L.begin(), L.end());
    int max_R = *max_element(R.begin(), R.end());
    int max_B = *max_element(B.begin(), B.end());
    int max_T = *max_element(T.begin(), T.end());
    int mx_H = -1;
    for (int i = 0; i < N; ++i) {
      if (L[i] == max_L && R[i] == max_R) mx_H = i;
    }
    if (mx_H == -1) bad = true;
    else {
      for (int i = 0; i < mx_H; ++i) {
        if (L[i] == -1) continue;
        if (L[i + 1] == -1 || L[i + 1] < L[i] || R[i + 1] < R[i]) bad = true;
      }    
      for (int i = mx_H + 1; i < N; ++i) {
        if (L[i] == -1) continue;
        if (L[i - 1] == -1 || L[i - 1] < L[i] || R[i - 1] < R[i]) bad = true;
      }
    } 
    vector<array<int, 2>> ranges;
    for (int i = 0; i < N; ++i) {
      if (L[i] != -1) ranges.push_back({L[i], R[i]});
    }
    sort(ranges.begin(), ranges.end());
    for (int i = 0; i < int(ranges.size()) - 1; ++i) {
      if (ranges[i + 1][1] < ranges[i][1]) bad = true;
    }
    if (bad) {
      return 0;
    } else {
      return N * N - tree_count;
    }
  }
  for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) for (int k = 0; k < N; ++k) for (int q = 0; q < N; ++q) dp[i][j][k][q] = -1e9;  
  int mx = 0;
  for (int u = N - 1; u >= 0; --u) {
    for (int d = u; d < N; ++d) {
      for (int l = 0; l < N; ++l) {
        for (int r = N - 1; r >= l; --r) {
          int& cur = dp[u][d][l][r];
          if (u == d) {
            int c = 0;
            for (int j = l; j <= r; ++j) c += F[u][j];
            if (c == 0) cur = r - l + 1;
            else continue;
          }    
          mx = max(mx, cur);
          if (l > 0) ckmax(cur, dp[u][d][l - 1][r]);
          if (r < N - 1) ckmax(cur, dp[u][d][l][r + 1]);
          if (u > 0) {
            int c = 0;
            for (int j = l; j <= r; ++j) c += F[u - 1][j];
            if (c == 0) {
              ckmax(dp[u - 1][d][l][r], cur + r - l + 1);
            }
          }
          if (d < N - 1) {
            int c = 0;
            for (int j = l; j <= r; ++j) c += F[d + 1][j];
            if (c == 0) {
              ckmax(dp[u][d + 1][l][r], cur + r - l + 1);
            }
          }
        }
      }
    }
  }
  return mx;
}

Compilation message

soccer.cpp: In function 'int biggest_stadium(int, std::vector<std::vector<int> >)':
soccer.cpp:63:9: warning: unused variable 'max_B' [-Wunused-variable]
   63 |     int max_B = *max_element(B.begin(), B.end());
      |         ^~~~~
soccer.cpp:64:9: warning: unused variable 'max_T' [-Wunused-variable]
   64 |     int max_T = *max_element(T.begin(), T.end());
      |         ^~~~~
soccer.cpp:30:46: warning: 'one_tree_j' may be used uninitialized in this function [-Wmaybe-uninitialized]
   30 |     return N * N - min(i + 1, N - i) * min(j + 1, N - j);
      |                                            ~~^~~
soccer.cpp:30:26: warning: 'one_tree_i' may be used uninitialized in this function [-Wmaybe-uninitialized]
   30 |     return N * N - min(i + 1, N - i) * min(j + 1, N - j);
      |                        ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 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 348 KB ok
4 Correct 0 ms 344 KB ok
5 Correct 0 ms 348 KB ok
6 Correct 0 ms 348 KB ok
7 Correct 1 ms 348 KB ok
8 Correct 12 ms 2208 KB ok
9 Correct 218 ms 31824 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB ok
2 Correct 0 ms 348 KB ok
3 Correct 1 ms 2396 KB ok
4 Correct 0 ms 2396 KB ok
5 Correct 0 ms 2396 KB ok
6 Correct 0 ms 2396 KB ok
7 Correct 1 ms 2396 KB ok
8 Correct 0 ms 2396 KB ok
9 Correct 0 ms 348 KB ok
10 Correct 0 ms 2396 KB ok
11 Correct 1 ms 2396 KB ok
12 Correct 0 ms 2396 KB ok
13 Correct 1 ms 2392 KB ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB ok
2 Correct 0 ms 344 KB ok
3 Correct 0 ms 348 KB ok
4 Correct 1 ms 2396 KB ok
5 Correct 0 ms 2396 KB ok
6 Correct 0 ms 2396 KB ok
7 Correct 0 ms 2396 KB ok
8 Correct 1 ms 2396 KB ok
9 Correct 0 ms 2396 KB ok
10 Correct 0 ms 348 KB ok
11 Correct 0 ms 2396 KB ok
12 Correct 1 ms 2396 KB ok
13 Correct 0 ms 2396 KB ok
14 Correct 1 ms 2392 KB ok
15 Correct 1 ms 2396 KB ok
16 Correct 0 ms 2396 KB ok
17 Correct 1 ms 2396 KB ok
18 Correct 0 ms 2396 KB ok
19 Correct 1 ms 2396 KB ok
20 Correct 1 ms 2396 KB ok
21 Correct 1 ms 2396 KB ok
22 Correct 0 ms 2396 KB ok
23 Correct 0 ms 2392 KB ok
24 Correct 0 ms 2396 KB ok
25 Correct 0 ms 2396 KB ok
26 Correct 0 ms 2396 KB ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB ok
2 Correct 0 ms 344 KB ok
3 Correct 0 ms 348 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 0 ms 344 KB ok
6 Correct 1 ms 2396 KB ok
7 Correct 0 ms 2396 KB ok
8 Correct 0 ms 2396 KB ok
9 Correct 0 ms 2396 KB ok
10 Correct 1 ms 2396 KB ok
11 Correct 0 ms 2396 KB ok
12 Correct 0 ms 348 KB ok
13 Correct 0 ms 2396 KB ok
14 Correct 1 ms 2396 KB ok
15 Correct 0 ms 2396 KB ok
16 Correct 1 ms 2392 KB ok
17 Correct 1 ms 2396 KB ok
18 Correct 0 ms 2396 KB ok
19 Correct 1 ms 2396 KB ok
20 Correct 0 ms 2396 KB ok
21 Correct 1 ms 2396 KB ok
22 Correct 1 ms 2396 KB ok
23 Correct 1 ms 2396 KB ok
24 Correct 0 ms 2396 KB ok
25 Correct 0 ms 2392 KB ok
26 Correct 0 ms 2396 KB ok
27 Correct 0 ms 2396 KB ok
28 Correct 0 ms 2396 KB ok
29 Correct 1 ms 2648 KB ok
30 Correct 4 ms 3420 KB ok
31 Correct 4 ms 3420 KB ok
32 Correct 4 ms 3420 KB ok
33 Correct 4 ms 3608 KB ok
34 Correct 4 ms 3612 KB ok
35 Correct 4 ms 3420 KB ok
36 Correct 4 ms 3420 KB ok
37 Correct 4 ms 3420 KB ok
38 Correct 4 ms 3480 KB ok
39 Correct 4 ms 3612 KB ok
40 Correct 4 ms 3420 KB ok
41 Correct 4 ms 3420 KB ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB ok
2 Correct 0 ms 344 KB ok
3 Correct 0 ms 348 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 0 ms 344 KB ok
6 Correct 1 ms 2396 KB ok
7 Correct 0 ms 2396 KB ok
8 Correct 0 ms 2396 KB ok
9 Correct 0 ms 2396 KB ok
10 Correct 1 ms 2396 KB ok
11 Correct 0 ms 2396 KB ok
12 Correct 0 ms 348 KB ok
13 Correct 0 ms 2396 KB ok
14 Correct 1 ms 2396 KB ok
15 Correct 0 ms 2396 KB ok
16 Correct 1 ms 2392 KB ok
17 Correct 1 ms 2396 KB ok
18 Correct 0 ms 2396 KB ok
19 Correct 1 ms 2396 KB ok
20 Correct 0 ms 2396 KB ok
21 Correct 1 ms 2396 KB ok
22 Correct 1 ms 2396 KB ok
23 Correct 1 ms 2396 KB ok
24 Correct 0 ms 2396 KB ok
25 Correct 0 ms 2392 KB ok
26 Correct 0 ms 2396 KB ok
27 Correct 0 ms 2396 KB ok
28 Correct 0 ms 2396 KB ok
29 Correct 1 ms 2648 KB ok
30 Correct 4 ms 3420 KB ok
31 Correct 4 ms 3420 KB ok
32 Correct 4 ms 3420 KB ok
33 Correct 4 ms 3608 KB ok
34 Correct 4 ms 3612 KB ok
35 Correct 4 ms 3420 KB ok
36 Correct 4 ms 3420 KB ok
37 Correct 4 ms 3420 KB ok
38 Correct 4 ms 3480 KB ok
39 Correct 4 ms 3612 KB ok
40 Correct 4 ms 3420 KB ok
41 Correct 4 ms 3420 KB ok
42 Partially correct 13 ms 2396 KB partial
43 Partially correct 14 ms 2908 KB partial
44 Partially correct 14 ms 2700 KB partial
45 Partially correct 13 ms 2696 KB partial
46 Partially correct 13 ms 2908 KB partial
47 Partially correct 14 ms 2908 KB partial
48 Correct 13 ms 2904 KB ok
49 Partially correct 12 ms 2908 KB partial
50 Partially correct 13 ms 2904 KB partial
51 Partially correct 14 ms 2908 KB partial
52 Partially correct 13 ms 2908 KB partial
53 Partially correct 16 ms 2904 KB partial
54 Partially correct 12 ms 2908 KB partial
55 Partially correct 13 ms 2908 KB partial
56 Partially correct 13 ms 2908 KB partial
57 Partially correct 15 ms 2908 KB partial
58 Partially correct 13 ms 2756 KB partial
59 Partially correct 13 ms 2904 KB partial
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB ok
2 Correct 0 ms 344 KB ok
3 Correct 0 ms 348 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 0 ms 344 KB ok
6 Correct 0 ms 348 KB ok
7 Correct 0 ms 348 KB ok
8 Correct 1 ms 348 KB ok
9 Correct 12 ms 2208 KB ok
10 Correct 218 ms 31824 KB ok
11 Correct 1 ms 2396 KB ok
12 Correct 0 ms 2396 KB ok
13 Correct 0 ms 2396 KB ok
14 Correct 0 ms 2396 KB ok
15 Correct 1 ms 2396 KB ok
16 Correct 0 ms 2396 KB ok
17 Correct 0 ms 348 KB ok
18 Correct 0 ms 2396 KB ok
19 Correct 1 ms 2396 KB ok
20 Correct 0 ms 2396 KB ok
21 Correct 1 ms 2392 KB ok
22 Correct 1 ms 2396 KB ok
23 Correct 0 ms 2396 KB ok
24 Correct 1 ms 2396 KB ok
25 Correct 0 ms 2396 KB ok
26 Correct 1 ms 2396 KB ok
27 Correct 1 ms 2396 KB ok
28 Correct 1 ms 2396 KB ok
29 Correct 0 ms 2396 KB ok
30 Correct 0 ms 2392 KB ok
31 Correct 0 ms 2396 KB ok
32 Correct 0 ms 2396 KB ok
33 Correct 0 ms 2396 KB ok
34 Correct 1 ms 2648 KB ok
35 Correct 4 ms 3420 KB ok
36 Correct 4 ms 3420 KB ok
37 Correct 4 ms 3420 KB ok
38 Correct 4 ms 3608 KB ok
39 Correct 4 ms 3612 KB ok
40 Correct 4 ms 3420 KB ok
41 Correct 4 ms 3420 KB ok
42 Correct 4 ms 3420 KB ok
43 Correct 4 ms 3480 KB ok
44 Correct 4 ms 3612 KB ok
45 Correct 4 ms 3420 KB ok
46 Correct 4 ms 3420 KB ok
47 Partially correct 13 ms 2396 KB partial
48 Partially correct 14 ms 2908 KB partial
49 Partially correct 14 ms 2700 KB partial
50 Partially correct 13 ms 2696 KB partial
51 Partially correct 13 ms 2908 KB partial
52 Partially correct 14 ms 2908 KB partial
53 Correct 13 ms 2904 KB ok
54 Partially correct 12 ms 2908 KB partial
55 Partially correct 13 ms 2904 KB partial
56 Partially correct 14 ms 2908 KB partial
57 Partially correct 13 ms 2908 KB partial
58 Partially correct 16 ms 2904 KB partial
59 Partially correct 12 ms 2908 KB partial
60 Partially correct 13 ms 2908 KB partial
61 Partially correct 13 ms 2908 KB partial
62 Partially correct 15 ms 2908 KB partial
63 Partially correct 13 ms 2756 KB partial
64 Partially correct 13 ms 2904 KB partial
65 Partially correct 263 ms 35924 KB partial
66 Partially correct 239 ms 35916 KB partial
67 Partially correct 222 ms 35924 KB partial
68 Partially correct 228 ms 35928 KB partial
69 Partially correct 213 ms 35900 KB partial
70 Partially correct 206 ms 35956 KB partial
71 Partially correct 204 ms 35916 KB partial
72 Partially correct 209 ms 35868 KB partial
73 Correct 199 ms 35920 KB ok
74 Correct 216 ms 35840 KB ok
75 Partially correct 200 ms 35872 KB partial
76 Partially correct 204 ms 35924 KB partial
77 Partially correct 204 ms 35896 KB partial
78 Partially correct 196 ms 31828 KB partial
79 Partially correct 214 ms 31772 KB partial
80 Partially correct 194 ms 31828 KB partial
81 Partially correct 215 ms 31828 KB partial
82 Partially correct 190 ms 31824 KB partial
83 Partially correct 209 ms 31828 KB partial
84 Partially correct 203 ms 31772 KB partial
85 Partially correct 192 ms 31776 KB partial
86 Partially correct 199 ms 31828 KB partial
87 Partially correct 213 ms 31780 KB partial
88 Partially correct 209 ms 31772 KB partial
89 Partially correct 204 ms 31828 KB partial
90 Partially correct 199 ms 31784 KB partial
91 Partially correct 215 ms 31768 KB partial
92 Partially correct 207 ms 31776 KB partial
93 Partially correct 210 ms 31828 KB partial
94 Partially correct 194 ms 31772 KB partial
95 Partially correct 194 ms 31824 KB partial
96 Partially correct 222 ms 31824 KB partial
97 Partially correct 214 ms 31824 KB partial
98 Partially correct 232 ms 31828 KB partial
99 Partially correct 208 ms 31828 KB partial
100 Partially correct 194 ms 31828 KB partial
101 Partially correct 225 ms 31832 KB partial
102 Partially correct 203 ms 31828 KB partial
103 Partially correct 194 ms 31828 KB partial
104 Partially correct 197 ms 31824 KB partial
105 Partially correct 193 ms 31824 KB partial
106 Partially correct 201 ms 31824 KB partial
107 Partially correct 193 ms 31776 KB partial
108 Partially correct 203 ms 31824 KB partial
109 Partially correct 209 ms 31828 KB partial