답안 #855527

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
855527 2023-10-01T11:45:27 Z tvladm2009 Giraffes (JOI22_giraffes) C++17
59 / 100
31 ms 111188 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N = 300 + 7;
int a[N], pos[N], dp[N][N][N];

int main() {
#ifdef ONPC
  freopen("input.txt", "r", stdin);
#else
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif // ONPC

  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  for (int len = 1; len <= n; len++) {
    for (int l = 1; l + len - 1 <= n; l++) {
      for (int t = 1; t + len - 1 <= n; t++) {
        int r = l + len - 1;
        int tt = t + len - 1;

        if (a[l] == t) {
          dp[len][l][t] = dp[len - 1][l + 1][t + 1] + 1;
        } else if (a[r] == t) {
          dp[len][l][t] = dp[len - 1][l][t + 1] + 1;
        } else if (a[l] == tt) {
          dp[len][l][t] = dp[len - 1][l + 1][t] + 1;
        } else if (a[r] == tt) {
          dp[len][l][t] = dp[len - 1][l][t] + 1;
        } else {
          dp[len][l][t] = max({dp[len - 1][l][t], dp[len - 1][l + 1][t], dp[len - 1][l][t + 1], dp[len - 1][l + 1][t + 1]});
        }
      }
    }
  }
  cout << n - dp[n][1][1] << "\n";
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4560 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 6620 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4560 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 6620 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6488 KB Output is correct
21 Correct 2 ms 12636 KB Output is correct
22 Correct 5 ms 37368 KB Output is correct
23 Correct 12 ms 70180 KB Output is correct
24 Correct 18 ms 90712 KB Output is correct
25 Correct 26 ms 107040 KB Output is correct
26 Correct 28 ms 111184 KB Output is correct
27 Correct 31 ms 111100 KB Output is correct
28 Correct 28 ms 111184 KB Output is correct
29 Correct 31 ms 111072 KB Output is correct
30 Correct 29 ms 111188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4560 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 6620 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6488 KB Output is correct
21 Correct 2 ms 12636 KB Output is correct
22 Correct 5 ms 37368 KB Output is correct
23 Correct 12 ms 70180 KB Output is correct
24 Correct 18 ms 90712 KB Output is correct
25 Correct 26 ms 107040 KB Output is correct
26 Correct 28 ms 111184 KB Output is correct
27 Correct 31 ms 111100 KB Output is correct
28 Correct 28 ms 111184 KB Output is correct
29 Correct 31 ms 111072 KB Output is correct
30 Correct 29 ms 111188 KB Output is correct
31 Runtime error 3 ms 600 KB Execution killed with signal 11
32 Halted 0 ms 0 KB -