답안 #841914

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
841914 2023-09-02T08:27:21 Z flashmt 축구 경기장 (IOI23_soccer) C++17
65.5 / 100
374 ms 47980 KB
#include "soccer.h"
// #include "Debug.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 33;

int f[N][N][N][N];

int isBad(vector<pair<int, int>> a)
{
  int len = size(a);
  for (int i = 0; i < len; i++)
    for (int j = i + 1; j < len; j++)
    {
      auto [l, r] = a[i];
      auto [ll, rr] = a[j];
      int intersect = min(r, rr) - max(l, ll);
      if (intersect >= 0 && intersect < min(r - l, rr - ll))
        return 1;
    }
  return 0;
}

void update(int &x, int y)
{
  x = max(x, y);
}

int biggest_stadium(int n, std::vector<std::vector<int>> a)
{
  int area = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      area += 1 - a[i][j];

  if (area == n * n - 1)
  {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        if (a[i][j])
        {
          int exclude = min(i + 1, n - i) * min(j + 1, n - j);
          return n * n - exclude;
        }
  }

  int canUseAll = 1;

  vector<vector<pair<int, int>>> rows(n);
  vector<pair<int, int>> allRows;
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < n;)
      if (a[i][j]) j++;
      else
      {
        int jj = j + 1;
        while (jj < n && !a[i][jj])
          jj++;
        rows[i].push_back({j, jj - 1});
        j = jj;
      }

    if (size(rows[i]) > 1) canUseAll = 0;
    else if (size(rows[i]) == 1) allRows.push_back(rows[i][0]);
  }

  vector<vector<pair<int, int>>> cols(n);
  vector<pair<int, int>> allCols;
  for (int j = 0; j < n; j++)
  {
    for (int i = 0; i < n;)
      if (a[i][j]) i++;
      else
      {
        int ii = i + 1;
        while (ii < n && !a[ii][j])
          ii++;
        cols[j].push_back({i, ii - 1});
        i = ii;
      }

    if (size(cols[j]) > 1) canUseAll = 0;
    else if (size(cols[j]) == 1) allCols.push_back(cols[j][0]);
  }

  canUseAll &= !isBad(allRows) && !isBad(allCols);
  if (canUseAll)
    return area;

  if (n <= N)
  {
    for (int i = 0; i < n; i++)
      for (auto [l, r] : rows[i])
        f[i][i][l][r] = r - l + 1;

    int ans = 0;
    for (int len = 1; len < n; len++)
      for (int i = 0; i + len <= n; i++)
        for (int j = 0; j < n; j++)
          for (int jj = j; jj < n; jj++)
          {
            int ii = i + len - 1;
            if (!f[i][ii][j][jj])
              continue;

            ans = max(ans, f[i][ii][j][jj]);

            if (i)
            {
              for (auto [l, r] : rows[i - 1])
              {
                int k = max(j, l), kk = min(jj, r);
                if (k <= kk)
                  update(f[i - 1][ii][k][kk], f[i][ii][j][jj] + kk - k + 1);
              }
            }

            if (ii + 1 < n)
            {
              for (auto [l, r] : rows[ii + 1])
              {
                int k = max(j, l), kk = min(jj, r);
                if (k <= kk)
                  update(f[i][ii + 1][k][kk], f[i][ii][j][jj] + kk - k + 1);
              }
            }
          }

    for (int j = 0; j < n; j++)
      for (int jj = j; jj < n; jj++)
        ans = max(ans, f[0][n - 1][j][jj]);

    return ans;
  }

  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 1 ms 344 KB ok
6 Correct 0 ms 344 KB ok
7 Correct 1 ms 344 KB ok
8 Correct 18 ms 2392 KB ok
9 Correct 305 ms 31824 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB ok
2 Correct 0 ms 344 KB ok
3 Correct 1 ms 2392 KB ok
4 Correct 1 ms 2396 KB ok
5 Correct 1 ms 2392 KB ok
6 Correct 1 ms 2396 KB ok
7 Correct 1 ms 2392 KB ok
8 Correct 0 ms 348 KB ok
9 Correct 0 ms 348 KB ok
10 Correct 0 ms 2396 KB ok
11 Correct 1 ms 2392 KB ok
12 Correct 1 ms 2392 KB ok
13 Correct 0 ms 348 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB ok
2 Correct 0 ms 344 KB ok
3 Correct 0 ms 344 KB ok
4 Correct 1 ms 2392 KB ok
5 Correct 1 ms 2396 KB ok
6 Correct 1 ms 2392 KB ok
7 Correct 1 ms 2396 KB ok
8 Correct 1 ms 2392 KB ok
9 Correct 0 ms 348 KB ok
10 Correct 0 ms 348 KB ok
11 Correct 0 ms 2396 KB ok
12 Correct 1 ms 2392 KB ok
13 Correct 1 ms 2392 KB ok
14 Correct 0 ms 348 KB ok
15 Correct 1 ms 2392 KB ok
16 Correct 1 ms 2396 KB ok
17 Correct 1 ms 2392 KB ok
18 Correct 1 ms 2396 KB ok
19 Correct 1 ms 2392 KB ok
20 Correct 0 ms 344 KB ok
21 Correct 1 ms 344 KB ok
22 Correct 1 ms 2392 KB ok
23 Correct 1 ms 2392 KB ok
24 Correct 1 ms 2392 KB ok
25 Correct 0 ms 2396 KB ok
26 Correct 0 ms 2396 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB ok
2 Correct 0 ms 344 KB ok
3 Correct 0 ms 344 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 0 ms 348 KB ok
6 Correct 1 ms 2392 KB ok
7 Correct 1 ms 2396 KB ok
8 Correct 1 ms 2392 KB ok
9 Correct 1 ms 2396 KB ok
10 Correct 1 ms 2392 KB ok
11 Correct 0 ms 348 KB ok
12 Correct 0 ms 348 KB ok
13 Correct 0 ms 2396 KB ok
14 Correct 1 ms 2392 KB ok
15 Correct 1 ms 2392 KB ok
16 Correct 0 ms 348 KB ok
17 Correct 1 ms 2392 KB ok
18 Correct 1 ms 2396 KB ok
19 Correct 1 ms 2392 KB ok
20 Correct 1 ms 2396 KB ok
21 Correct 1 ms 2392 KB ok
22 Correct 0 ms 344 KB ok
23 Correct 1 ms 344 KB ok
24 Correct 1 ms 2392 KB ok
25 Correct 1 ms 2392 KB ok
26 Correct 1 ms 2392 KB ok
27 Correct 0 ms 2396 KB ok
28 Correct 0 ms 2396 KB ok
29 Correct 1 ms 2392 KB ok
30 Correct 1 ms 4696 KB ok
31 Correct 1 ms 4440 KB ok
32 Correct 1 ms 4440 KB ok
33 Correct 1 ms 4440 KB ok
34 Correct 0 ms 344 KB ok
35 Correct 0 ms 344 KB ok
36 Correct 1 ms 2396 KB ok
37 Correct 1 ms 4440 KB ok
38 Correct 1 ms 4444 KB ok
39 Correct 1 ms 4696 KB ok
40 Correct 1 ms 4440 KB ok
41 Correct 1 ms 4444 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB ok
2 Correct 0 ms 344 KB ok
3 Correct 0 ms 344 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 0 ms 348 KB ok
6 Correct 1 ms 2392 KB ok
7 Correct 1 ms 2396 KB ok
8 Correct 1 ms 2392 KB ok
9 Correct 1 ms 2396 KB ok
10 Correct 1 ms 2392 KB ok
11 Correct 0 ms 348 KB ok
12 Correct 0 ms 348 KB ok
13 Correct 0 ms 2396 KB ok
14 Correct 1 ms 2392 KB ok
15 Correct 1 ms 2392 KB ok
16 Correct 0 ms 348 KB ok
17 Correct 1 ms 2392 KB ok
18 Correct 1 ms 2396 KB ok
19 Correct 1 ms 2392 KB ok
20 Correct 1 ms 2396 KB ok
21 Correct 1 ms 2392 KB ok
22 Correct 0 ms 344 KB ok
23 Correct 1 ms 344 KB ok
24 Correct 1 ms 2392 KB ok
25 Correct 1 ms 2392 KB ok
26 Correct 1 ms 2392 KB ok
27 Correct 0 ms 2396 KB ok
28 Correct 0 ms 2396 KB ok
29 Correct 1 ms 2392 KB ok
30 Correct 1 ms 4696 KB ok
31 Correct 1 ms 4440 KB ok
32 Correct 1 ms 4440 KB ok
33 Correct 1 ms 4440 KB ok
34 Correct 0 ms 344 KB ok
35 Correct 0 ms 344 KB ok
36 Correct 1 ms 2396 KB ok
37 Correct 1 ms 4440 KB ok
38 Correct 1 ms 4444 KB ok
39 Correct 1 ms 4696 KB ok
40 Correct 1 ms 4440 KB ok
41 Correct 1 ms 4444 KB ok
42 Partially correct 20 ms 2904 KB partial
43 Partially correct 25 ms 3224 KB partial
44 Partially correct 19 ms 2384 KB partial
45 Partially correct 19 ms 2384 KB partial
46 Partially correct 20 ms 2648 KB partial
47 Partially correct 19 ms 2396 KB partial
48 Correct 21 ms 2392 KB ok
49 Partially correct 21 ms 2392 KB partial
50 Partially correct 20 ms 3416 KB partial
51 Partially correct 20 ms 2648 KB partial
52 Partially correct 19 ms 2392 KB partial
53 Partially correct 19 ms 2392 KB partial
54 Partially correct 19 ms 2392 KB partial
55 Partially correct 19 ms 2392 KB partial
56 Partially correct 19 ms 2392 KB partial
57 Partially correct 19 ms 2392 KB partial
58 Partially correct 19 ms 2396 KB partial
59 Partially correct 19 ms 2392 KB partial
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB ok
2 Correct 0 ms 344 KB ok
3 Correct 0 ms 344 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 344 KB ok
8 Correct 1 ms 344 KB ok
9 Correct 18 ms 2392 KB ok
10 Correct 305 ms 31824 KB ok
11 Correct 1 ms 2392 KB ok
12 Correct 1 ms 2396 KB ok
13 Correct 1 ms 2392 KB ok
14 Correct 1 ms 2396 KB ok
15 Correct 1 ms 2392 KB ok
16 Correct 0 ms 348 KB ok
17 Correct 0 ms 348 KB ok
18 Correct 0 ms 2396 KB ok
19 Correct 1 ms 2392 KB ok
20 Correct 1 ms 2392 KB ok
21 Correct 0 ms 348 KB ok
22 Correct 1 ms 2392 KB ok
23 Correct 1 ms 2396 KB ok
24 Correct 1 ms 2392 KB ok
25 Correct 1 ms 2396 KB ok
26 Correct 1 ms 2392 KB ok
27 Correct 0 ms 344 KB ok
28 Correct 1 ms 344 KB ok
29 Correct 1 ms 2392 KB ok
30 Correct 1 ms 2392 KB ok
31 Correct 1 ms 2392 KB ok
32 Correct 0 ms 2396 KB ok
33 Correct 0 ms 2396 KB ok
34 Correct 1 ms 2392 KB ok
35 Correct 1 ms 4696 KB ok
36 Correct 1 ms 4440 KB ok
37 Correct 1 ms 4440 KB ok
38 Correct 1 ms 4440 KB ok
39 Correct 0 ms 344 KB ok
40 Correct 0 ms 344 KB ok
41 Correct 1 ms 2396 KB ok
42 Correct 1 ms 4440 KB ok
43 Correct 1 ms 4444 KB ok
44 Correct 1 ms 4696 KB ok
45 Correct 1 ms 4440 KB ok
46 Correct 1 ms 4444 KB ok
47 Partially correct 20 ms 2904 KB partial
48 Partially correct 25 ms 3224 KB partial
49 Partially correct 19 ms 2384 KB partial
50 Partially correct 19 ms 2384 KB partial
51 Partially correct 20 ms 2648 KB partial
52 Partially correct 19 ms 2396 KB partial
53 Correct 21 ms 2392 KB ok
54 Partially correct 21 ms 2392 KB partial
55 Partially correct 20 ms 3416 KB partial
56 Partially correct 20 ms 2648 KB partial
57 Partially correct 19 ms 2392 KB partial
58 Partially correct 19 ms 2392 KB partial
59 Partially correct 19 ms 2392 KB partial
60 Partially correct 19 ms 2392 KB partial
61 Partially correct 19 ms 2392 KB partial
62 Partially correct 19 ms 2392 KB partial
63 Partially correct 19 ms 2396 KB partial
64 Partially correct 19 ms 2392 KB partial
65 Partially correct 324 ms 40016 KB partial
66 Partially correct 363 ms 47980 KB partial
67 Partially correct 342 ms 40016 KB partial
68 Partially correct 312 ms 32344 KB partial
69 Partially correct 304 ms 32848 KB partial
70 Partially correct 313 ms 33824 KB partial
71 Partially correct 358 ms 32036 KB partial
72 Partially correct 316 ms 32028 KB partial
73 Correct 340 ms 32028 KB ok
74 Correct 316 ms 32080 KB ok
75 Partially correct 374 ms 32032 KB partial
76 Partially correct 327 ms 47904 KB partial
77 Partially correct 324 ms 47896 KB partial
78 Partially correct 324 ms 35408 KB partial
79 Partially correct 320 ms 33616 KB partial
80 Partially correct 318 ms 33104 KB partial
81 Partially correct 325 ms 32888 KB partial
82 Partially correct 314 ms 32852 KB partial
83 Partially correct 347 ms 38692 KB partial
84 Partially correct 330 ms 32036 KB partial
85 Partially correct 343 ms 32032 KB partial
86 Partially correct 323 ms 32288 KB partial
87 Partially correct 327 ms 32032 KB partial
88 Partially correct 342 ms 32032 KB partial
89 Partially correct 341 ms 32068 KB partial
90 Partially correct 336 ms 32032 KB partial
91 Partially correct 319 ms 32080 KB partial
92 Partially correct 349 ms 38028 KB partial
93 Partially correct 333 ms 38228 KB partial
94 Partially correct 319 ms 35408 KB partial
95 Partially correct 311 ms 35868 KB partial
96 Partially correct 312 ms 35872 KB partial
97 Partially correct 314 ms 35612 KB partial
98 Partially correct 310 ms 33872 KB partial
99 Partially correct 362 ms 35868 KB partial
100 Partially correct 305 ms 32028 KB partial
101 Partially correct 301 ms 32084 KB partial
102 Partially correct 312 ms 32080 KB partial
103 Partially correct 300 ms 32080 KB partial
104 Partially correct 307 ms 32032 KB partial
105 Partially correct 301 ms 32028 KB partial
106 Partially correct 308 ms 32036 KB partial
107 Partially correct 310 ms 32036 KB partial
108 Partially correct 372 ms 38108 KB partial
109 Partially correct 337 ms 37756 KB partial