Submission #900227

# Submission time Handle Problem Language Result Execution time Memory
900227 2024-01-07T23:09:13 Z MilosMilutinovic Soccer Stadium (IOI23_soccer) C++17
0 / 100
4500 ms 19972 KB
#include "soccer.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 52;

int dp[N][N][N][N];

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

bool check_all(int n, vector<vector<int>> a) {
  vector<vector<bool>> was(n, vector<bool>(n));
  function<void(int, int)> Dfs = [&](int x, int y) {
    if (x < 0 || x >= n || y < 0 || y >= n || a[x][y] == 1 || was[x][y]) {
      return;
    }
    was[x][y] = true;
    for (int d = 0; d < 4; d++) {
      Dfs(x + dx[d], y + dy[d]);
    }
  };
  bool done = false;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (!done && a[i][j] == 0) {
        Dfs(i, j);
        done = true;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (a[i][j] == 0 && !was[i][j]) {
        return false;
      }
    }
  }
  vector<pair<int, int>> seg;
  for (int j = 0; j < n; j++) {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (a[i][j] == 1) {
        continue;
      }
      cnt += 1;
      if (cnt == 2) {
        return false;
      }
      int ptr = i;
      while (ptr + 1 < n && a[ptr + 1][j] == 0) {
        ptr += 1;
      }
      seg.emplace_back(i, ptr);
      i = ptr;
    }
  }
  int sz = (int) seg.size();
  int mx = 0;
  for (int i = 1; i < sz; i++) {
    if (seg[i].second - seg[i].first > seg[mx].second - seg[mx].first) {
      mx = i;
    }
  }
  int l = mx, r = mx, lst = mx;
  while (l != 0 || r != sz - 1) {
    if (l == 0 || (r + 1 < sz && seg[r + 1].second - seg[r + 1].first > seg[l - 1].second - seg[l - 1].first)) {
      if (!(seg[lst].first <= seg[r + 1].first && seg[r + 1].second <= seg[lst].second)) {
        return false;
      }
      r += 1;
      lst = r;
    } else {
      if (!(seg[lst].first <= seg[l - 1].first && seg[l - 1].second <= seg[lst].second)) {
        return false;
      }
      l -= 1;
      lst = l;
    }
  }
  return true;
}

int biggest_stadium(int n, vector<vector<int>> a) {
  if (check_all(n, a)) {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (a[i][j] == 0) {
          cnt += 1;
        }
      }
    }
    return cnt;
  }
  for (int r = 0; r < n; r++) {
    for (int l = r; l >= 0; l--) {
      if (l == r) {
        for (int i = 0; i < n; i++) {
          int cnt = 0;
          for (int j = i; j < n; j++) {
            cnt += 1;
            if (a[l][j] == 1) {
              break;
            }
            dp[l][r][i][j] = cnt;
          }
        }
        continue;
      }
      {
        // left
        for (int i = 0; i < n; i++) {
          for (int j = i; j < n; j++) {
            if (a[l][j] == 1) {
              break;
            }
            for (int x = 0; x <= i; x++) {
              for (int y = j; y < n; y++) {
                dp[l][r][i][j] = max(dp[l][r][i][j], dp[l + 1][r][x][y] + (j - i + 1));
              }
            }
          }
        }
      }
      {
        // right
        for (int i = 0; i < n; i++) {
          for (int j = i; j < n; j++) {
            if (a[r][j] == 1) {
              break;
            }
            for (int x = 0; x <= i; x++) {
              for (int y = j; y < n; y++) {
                dp[l][r][i][j] = max(dp[l][r][i][j], dp[l][r - 1][x][y] + (j - i + 1));
              }
            }
          }
        }
      }
    }
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int x = 0; x < n; x++) {
        for (int y = 0; y < n; y++) {
          res = max(res, dp[i][j][x][y]);
        }
      }
    }
  }
  return res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB ok
2 Correct 0 ms 348 KB ok
3 Correct 0 ms 348 KB ok
4 Correct 0 ms 600 KB ok
5 Correct 0 ms 348 KB ok
6 Partially correct 1 ms 2396 KB partial
7 Execution timed out 4583 ms 19972 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB ok
2 Correct 0 ms 348 KB ok
3 Correct 1 ms 2392 KB ok
4 Correct 0 ms 2396 KB ok
5 Correct 1 ms 2548 KB ok
6 Correct 0 ms 2396 KB ok
7 Correct 1 ms 2396 KB ok
8 Correct 0 ms 348 KB ok
9 Correct 0 ms 344 KB ok
10 Correct 1 ms 2396 KB ok
11 Incorrect 0 ms 348 KB wrong
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB ok
2 Correct 0 ms 348 KB ok
3 Correct 0 ms 348 KB ok
4 Correct 1 ms 2392 KB ok
5 Correct 0 ms 2396 KB ok
6 Correct 1 ms 2548 KB ok
7 Correct 0 ms 2396 KB ok
8 Correct 1 ms 2396 KB ok
9 Correct 0 ms 348 KB ok
10 Correct 0 ms 344 KB ok
11 Correct 1 ms 2396 KB ok
12 Incorrect 0 ms 348 KB wrong
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB ok
2 Correct 0 ms 348 KB ok
3 Correct 0 ms 348 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 0 ms 600 KB ok
6 Correct 1 ms 2392 KB ok
7 Correct 0 ms 2396 KB ok
8 Correct 1 ms 2548 KB ok
9 Correct 0 ms 2396 KB ok
10 Correct 1 ms 2396 KB ok
11 Correct 0 ms 348 KB ok
12 Correct 0 ms 344 KB ok
13 Correct 1 ms 2396 KB ok
14 Incorrect 0 ms 348 KB wrong
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB ok
2 Correct 0 ms 348 KB ok
3 Correct 0 ms 348 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 0 ms 600 KB ok
6 Correct 1 ms 2392 KB ok
7 Correct 0 ms 2396 KB ok
8 Correct 1 ms 2548 KB ok
9 Correct 0 ms 2396 KB ok
10 Correct 1 ms 2396 KB ok
11 Correct 0 ms 348 KB ok
12 Correct 0 ms 344 KB ok
13 Correct 1 ms 2396 KB ok
14 Incorrect 0 ms 348 KB wrong
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB ok
2 Correct 0 ms 348 KB ok
3 Correct 0 ms 348 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 0 ms 600 KB ok
6 Correct 0 ms 348 KB ok
7 Partially correct 1 ms 2396 KB partial
8 Execution timed out 4583 ms 19972 KB Time limit exceeded
9 Halted 0 ms 0 KB -