답안 #1017094

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017094 2024-07-08T20:38:51 Z MilosMilutinovic 축구 경기장 (IOI23_soccer) C++17
70 / 100
4500 ms 600220 KB
#include "soccer.h"
#include <bits/stdc++.h>
 
using namespace std;
 
const int MAX = 2005;
const int LOG = 12;
 
int n, a[MAX][MAX];
int L[MAX][MAX];
int R[MAX][MAX];
int U[MAX][MAX];
int D[MAX][MAX];
int go[MAX][MAX];
int sum[MAX][MAX];
int logs[MAX];
int st_U[MAX][MAX][LOG];
int st_D[MAX][MAX][LOG];
int res;
map<array<int, 4>, int> mp;
 
int query_U(int i, int l, int r) {
  int k = logs[r - l + 1];
  return max(st_U[i][l][k], st_U[i][r - (1 << k) + 1][k]);
}
 
int query_D(int i, int l, int r) {
  int k = logs[r - l + 1];
  return min(st_D[i][l][k], st_D[i][r - (1 << k) + 1][k]);
}

int get_sum(int i, int l, int r) {
  return sum[i][r] - (l == 0 ? 0 : sum[i][l - 1]);
}
 
void rec(int xl, int xr, int yl, int yr, int cur) {
  if (mp[{xl, xr, yl, yr}] >= cur) {
    return;
  }
  res = max(res, cur);
  mp[{xl, xr, yl, yr}] = cur;
  vector<array<int, 5>> to;
  if (xl > 0) {
    // up
    int ptr = yl;
    while (ptr <= yr) {
      if (a[xl - 1][ptr] == 1) {
        ptr = go[xl - 1][ptr];
        continue;
      }
      int t = min(yr, R[xl - 1][ptr]);
      int new_xl = query_U(xl - 1, ptr, t);
      if (ptr == yl && t == yr && ((yl > 0 && a[xl - 1][yl - 1] == 0) || (yr + 1 < n && a[xl - 1][yr + 1] == 0))) {
        ptr = R[xl - 1][ptr] + 1;
        continue;
      }
      int new_xr = ((xr == n - 1 || get_sum(xr + 1, ptr, t) > 0) ? xr : query_D(xr + 1, ptr, t));
      to.push_back({cur + (t - ptr + 1) * (xl - new_xl + new_xr - xr), new_xl, new_xr, ptr, t});
      //rec(new_xl, new_xr, ptr, t, cur + (t - ptr + 1) * (xl - new_xl + new_xr - xr));
      ptr = R[xl - 1][ptr] + 1;
    }
  }
  if (xr + 1 < n) {
    // down
    int ptr = yl;
    while (ptr <= yr) {
      if (a[xr + 1][ptr] == 1) {
        ptr = go[xr + 1][ptr];
        continue;
      }
      int t = min(yr, R[xr + 1][ptr]);
      int new_xr = query_D(xr + 1, ptr, t);
      if (ptr == yl && t == yr && ((yl > 0 && a[xr + 1][yl - 1] == 0) || (yr + 1 < n && a[xr + 1][yr + 1] == 0))) {
        ptr = R[xr + 1][ptr] + 1;
        continue;
      } 
      int new_xl = ((xl == 0 || get_sum(xl - 1, ptr, t) > 0) ? xl : query_U(xl - 1, ptr, t));
      to.push_back({cur + (t - ptr + 1) * (xl - new_xl + new_xr - xr), new_xl, new_xr, ptr, t});
      //rec(new_xl, new_xr, ptr, t, cur + (t - ptr + 1) * (xl - new_xl + new_xr - xr));
      ptr = R[xr + 1][ptr] + 1;
    }
  }
  sort(to.rbegin(), to.rend());
  for (int i = 0; i < (int) to.size(); i++) {
    rec(to[i][1], to[i][2], to[i][3], to[i][4], to[i][0]);
  }
}
 
int biggest_stadium(int N, vector<vector<int>> F) {
  n = N;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      a[i][j] = F[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      sum[i][j] = a[i][j];
      if (j > 0) {
        sum[i][j] += sum[i][j - 1];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (a[i][j] == 1) {
        continue;
      }
      int p = j;
      while (p + 1 < n && a[i][p + 1] == 0) {
        p += 1;
      }
      for (int k = j; k <= p; k++) {
        L[i][k] = j;
        R[i][k] = p;
      }
      j = p;
    }
  }
  for (int j = 0; j < n; j++) {
    for (int i = 0; i < n; i++) {
      if (a[i][j] == 1) {
        continue;
      }
      int p = i;
      while (p + 1 < n && a[p + 1][j] == 0) {
        p += 1;
      }
      for (int k = i; k <= p; k++) {
        U[k][j] = i;
        D[k][j] = p;
      }
      i = p;
    }
  }
  for (int i = 2; i <= n; i++) {
    logs[i] = logs[i >> 1] + 1;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      st_U[i][j][0] = U[i][j];
      st_D[i][j][0] = D[i][j];
    }
  }
  for (int k = 1; k < LOG; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j + (1 << k) <= n; j++) {
        st_U[i][j][k] = max(st_U[i][j][k - 1], st_U[i][j + (1 << (k - 1))][k - 1]);
        st_D[i][j][k] = min(st_D[i][j][k - 1], st_D[i][j + (1 << (k - 1))][k - 1]);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = n - 1; j >= 0; j--) {
      if (a[i][j] == 1) {
        go[i][j] = (j == n - 1 ? n : go[i][j + 1]);
      } else {
        go[i][j] = j;
      }
    }
  }
  res = 0;
  vector<array<int, 4>> s;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (a[i][j] == 1) {
        continue;
      }
      if (j == 0 || a[i][j - 1] == 1) {
        s.push_back({R[i][j] - j + 1, i, j, R[i][j]});
      }
    }
  }
  sort(s.rbegin(), s.rend());
  for (auto& p : s) {
    int i = p[1];
    int l = p[2], r = p[3];
    rec(i, i, l, r, r - l + 1);
  }
  return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 21080 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 20824 KB ok
2 Correct 2 ms 20828 KB ok
3 Correct 2 ms 20828 KB ok
4 Correct 2 ms 20824 KB ok
5 Correct 1 ms 16732 KB ok
6 Correct 2 ms 20960 KB ok
7 Correct 4 ms 43612 KB ok
8 Correct 32 ms 96604 KB ok
9 Correct 548 ms 519196 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 20824 KB ok
2 Correct 2 ms 20828 KB ok
3 Correct 3 ms 20824 KB ok
4 Correct 2 ms 21080 KB ok
5 Correct 2 ms 20824 KB ok
6 Correct 2 ms 20828 KB ok
7 Correct 2 ms 20824 KB ok
8 Correct 2 ms 20828 KB ok
9 Correct 2 ms 20828 KB ok
10 Correct 2 ms 20828 KB ok
11 Correct 2 ms 20828 KB ok
12 Correct 2 ms 20828 KB ok
13 Correct 2 ms 20828 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 21080 KB ok
2 Correct 2 ms 20824 KB ok
3 Correct 2 ms 20828 KB ok
4 Correct 3 ms 20824 KB ok
5 Correct 2 ms 21080 KB ok
6 Correct 2 ms 20824 KB ok
7 Correct 2 ms 20828 KB ok
8 Correct 2 ms 20824 KB ok
9 Correct 2 ms 20828 KB ok
10 Correct 2 ms 20828 KB ok
11 Correct 2 ms 20828 KB ok
12 Correct 2 ms 20828 KB ok
13 Correct 2 ms 20828 KB ok
14 Correct 2 ms 20828 KB ok
15 Correct 2 ms 20828 KB ok
16 Correct 2 ms 20828 KB ok
17 Correct 2 ms 20828 KB ok
18 Correct 2 ms 20824 KB ok
19 Correct 2 ms 20828 KB ok
20 Correct 2 ms 20828 KB ok
21 Correct 2 ms 20828 KB ok
22 Correct 2 ms 20828 KB ok
23 Correct 2 ms 20828 KB ok
24 Correct 2 ms 20828 KB ok
25 Correct 2 ms 20828 KB ok
26 Correct 2 ms 20828 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 21080 KB ok
2 Correct 2 ms 20824 KB ok
3 Correct 2 ms 20828 KB ok
4 Correct 2 ms 20828 KB ok
5 Correct 2 ms 20824 KB ok
6 Correct 3 ms 20824 KB ok
7 Correct 2 ms 21080 KB ok
8 Correct 2 ms 20824 KB ok
9 Correct 2 ms 20828 KB ok
10 Correct 2 ms 20824 KB ok
11 Correct 2 ms 20828 KB ok
12 Correct 2 ms 20828 KB ok
13 Correct 2 ms 20828 KB ok
14 Correct 2 ms 20828 KB ok
15 Correct 2 ms 20828 KB ok
16 Correct 2 ms 20828 KB ok
17 Correct 2 ms 20828 KB ok
18 Correct 2 ms 20828 KB ok
19 Correct 2 ms 20828 KB ok
20 Correct 2 ms 20824 KB ok
21 Correct 2 ms 20828 KB ok
22 Correct 2 ms 20828 KB ok
23 Correct 2 ms 20828 KB ok
24 Correct 2 ms 20828 KB ok
25 Correct 2 ms 20828 KB ok
26 Correct 2 ms 20828 KB ok
27 Correct 2 ms 20828 KB ok
28 Correct 2 ms 20828 KB ok
29 Correct 2 ms 20828 KB ok
30 Correct 3 ms 31068 KB ok
31 Correct 3 ms 31064 KB ok
32 Correct 4 ms 31068 KB ok
33 Correct 3 ms 31212 KB ok
34 Correct 3 ms 31068 KB ok
35 Correct 3 ms 31228 KB ok
36 Correct 3 ms 31068 KB ok
37 Correct 3 ms 31068 KB ok
38 Correct 3 ms 31184 KB ok
39 Correct 3 ms 31068 KB ok
40 Correct 3 ms 31068 KB ok
41 Correct 3 ms 31068 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 21080 KB ok
2 Correct 2 ms 20824 KB ok
3 Correct 2 ms 20828 KB ok
4 Correct 2 ms 20828 KB ok
5 Correct 2 ms 20824 KB ok
6 Correct 3 ms 20824 KB ok
7 Correct 2 ms 21080 KB ok
8 Correct 2 ms 20824 KB ok
9 Correct 2 ms 20828 KB ok
10 Correct 2 ms 20824 KB ok
11 Correct 2 ms 20828 KB ok
12 Correct 2 ms 20828 KB ok
13 Correct 2 ms 20828 KB ok
14 Correct 2 ms 20828 KB ok
15 Correct 2 ms 20828 KB ok
16 Correct 2 ms 20828 KB ok
17 Correct 2 ms 20828 KB ok
18 Correct 2 ms 20828 KB ok
19 Correct 2 ms 20828 KB ok
20 Correct 2 ms 20824 KB ok
21 Correct 2 ms 20828 KB ok
22 Correct 2 ms 20828 KB ok
23 Correct 2 ms 20828 KB ok
24 Correct 2 ms 20828 KB ok
25 Correct 2 ms 20828 KB ok
26 Correct 2 ms 20828 KB ok
27 Correct 2 ms 20828 KB ok
28 Correct 2 ms 20828 KB ok
29 Correct 2 ms 20828 KB ok
30 Correct 3 ms 31068 KB ok
31 Correct 3 ms 31064 KB ok
32 Correct 4 ms 31068 KB ok
33 Correct 3 ms 31212 KB ok
34 Correct 3 ms 31068 KB ok
35 Correct 3 ms 31228 KB ok
36 Correct 3 ms 31068 KB ok
37 Correct 3 ms 31068 KB ok
38 Correct 3 ms 31184 KB ok
39 Correct 3 ms 31068 KB ok
40 Correct 3 ms 31068 KB ok
41 Correct 3 ms 31068 KB ok
42 Correct 104 ms 102308 KB ok
43 Correct 113 ms 104136 KB ok
44 Correct 73 ms 98896 KB ok
45 Correct 70 ms 97108 KB ok
46 Correct 89 ms 100812 KB ok
47 Correct 33 ms 96340 KB ok
48 Correct 43 ms 97876 KB ok
49 Correct 40 ms 97424 KB ok
50 Correct 72 ms 101380 KB ok
51 Correct 52 ms 100032 KB ok
52 Correct 52 ms 94288 KB ok
53 Correct 34 ms 95060 KB ok
54 Correct 70 ms 95568 KB ok
55 Correct 87 ms 98140 KB ok
56 Correct 32 ms 95576 KB ok
57 Correct 57 ms 102172 KB ok
58 Correct 63 ms 101128 KB ok
59 Correct 68 ms 103248 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 21080 KB ok
2 Correct 2 ms 20824 KB ok
3 Correct 2 ms 20828 KB ok
4 Correct 2 ms 20828 KB ok
5 Correct 2 ms 20824 KB ok
6 Correct 1 ms 16732 KB ok
7 Correct 2 ms 20960 KB ok
8 Correct 4 ms 43612 KB ok
9 Correct 32 ms 96604 KB ok
10 Correct 548 ms 519196 KB ok
11 Correct 3 ms 20824 KB ok
12 Correct 2 ms 21080 KB ok
13 Correct 2 ms 20824 KB ok
14 Correct 2 ms 20828 KB ok
15 Correct 2 ms 20824 KB ok
16 Correct 2 ms 20828 KB ok
17 Correct 2 ms 20828 KB ok
18 Correct 2 ms 20828 KB ok
19 Correct 2 ms 20828 KB ok
20 Correct 2 ms 20828 KB ok
21 Correct 2 ms 20828 KB ok
22 Correct 2 ms 20828 KB ok
23 Correct 2 ms 20828 KB ok
24 Correct 2 ms 20828 KB ok
25 Correct 2 ms 20824 KB ok
26 Correct 2 ms 20828 KB ok
27 Correct 2 ms 20828 KB ok
28 Correct 2 ms 20828 KB ok
29 Correct 2 ms 20828 KB ok
30 Correct 2 ms 20828 KB ok
31 Correct 2 ms 20828 KB ok
32 Correct 2 ms 20828 KB ok
33 Correct 2 ms 20828 KB ok
34 Correct 2 ms 20828 KB ok
35 Correct 3 ms 31068 KB ok
36 Correct 3 ms 31064 KB ok
37 Correct 4 ms 31068 KB ok
38 Correct 3 ms 31212 KB ok
39 Correct 3 ms 31068 KB ok
40 Correct 3 ms 31228 KB ok
41 Correct 3 ms 31068 KB ok
42 Correct 3 ms 31068 KB ok
43 Correct 3 ms 31184 KB ok
44 Correct 3 ms 31068 KB ok
45 Correct 3 ms 31068 KB ok
46 Correct 3 ms 31068 KB ok
47 Correct 104 ms 102308 KB ok
48 Correct 113 ms 104136 KB ok
49 Correct 73 ms 98896 KB ok
50 Correct 70 ms 97108 KB ok
51 Correct 89 ms 100812 KB ok
52 Correct 33 ms 96340 KB ok
53 Correct 43 ms 97876 KB ok
54 Correct 40 ms 97424 KB ok
55 Correct 72 ms 101380 KB ok
56 Correct 52 ms 100032 KB ok
57 Correct 52 ms 94288 KB ok
58 Correct 34 ms 95060 KB ok
59 Correct 70 ms 95568 KB ok
60 Correct 87 ms 98140 KB ok
61 Correct 32 ms 95576 KB ok
62 Correct 57 ms 102172 KB ok
63 Correct 63 ms 101128 KB ok
64 Correct 68 ms 103248 KB ok
65 Correct 2238 ms 590004 KB ok
66 Correct 1094 ms 600220 KB ok
67 Correct 722 ms 549312 KB ok
68 Correct 1083 ms 521812 KB ok
69 Correct 1469 ms 535608 KB ok
70 Correct 1605 ms 547772 KB ok
71 Correct 911 ms 520648 KB ok
72 Correct 507 ms 519216 KB ok
73 Correct 795 ms 516120 KB ok
74 Correct 797 ms 516176 KB ok
75 Correct 795 ms 516312 KB ok
76 Correct 1321 ms 597408 KB ok
77 Correct 1270 ms 597396 KB ok
78 Correct 1946 ms 538040 KB ok
79 Correct 595 ms 527756 KB ok
80 Correct 570 ms 525764 KB ok
81 Correct 594 ms 525196 KB ok
82 Correct 836 ms 529676 KB ok
83 Correct 871 ms 553864 KB ok
84 Correct 889 ms 485596 KB ok
85 Correct 481 ms 477268 KB ok
86 Correct 1292 ms 489560 KB ok
87 Execution timed out 4578 ms 495952 KB Time limit exceeded
88 Halted 0 ms 0 KB -