답안 #1072929

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1072929 2024-08-24T07:28:59 Z kunzaZa183 Tortoise (CEOI21_tortoise) C++17
18 / 100
403 ms 436444 KB
#include <bits/stdc++.h>
using namespace std;
  const int maxn = 305;
  int dp[maxn * 2][maxn][maxn][2];
int main() {
  int n;
  cin>>n;
  vector<int> vi(n);
  for(auto &a:vi)
    cin>>a;

  for(int i = 0; i< maxn;i++)
    for(int j = 0; j < maxn; j++)
      for(int k = 0; k < maxn;k++)
        for(int l = 0; l < 2; l++)
          dp[i][j][k][l] = -1;

  auto repmax = [&](int &cur,int x) {
    cur = max(cur, x);
  };

  //tim, pos, last, has
  if(vi[0] >= 1) {
    dp[0][0][1][1] = 1;
  }else
    dp[0][0][0][0] = 0;

  for(int i = 0; i < 2*n ;i++)
    for(int j = 0; j < n; j++)
      for(int k = 0;k <= n; k++) {

        // cout<<i<<' '<<j<<' '<<k<<' '<<dp[i][j][k][0]<<' '<<dp[i][j][k][1]<<'\n';

        if(dp[i][j][k][0]!=-1 ){
          //send forward
          if(j + 1 < n) {
            repmax(dp[i + 1][j+1][k][0], dp[i][j][k][0]);

            if(vi[j+1] >= 1 && k <= j + 1 && i + 1 <= 2*(j+1)) {
              repmax(dp[i+1][j+1][j + 2][1], dp[i][j][k][0] + 1);
            }
          }
          //send back
          if(j - 1>= 0) {
            repmax(dp[i + 1][j-1][k][0], dp[i][j][k][0]);

            if(vi[j-1] >= 1 && k <= j - 1 && i + 1 <= 2*(j-1)) {
              repmax(dp[i+1][j - 1][j][1], dp[i][j][k][0] + 1);
            }
          }
        }

        if(dp[i][j][k][1] != -1) {
          if(j + 1 < n) {
            if(vi[j+1] == -1) {
              repmax(dp[i+1][j + 1][k][0], dp[i][j][k][1]);
            }else
            repmax(dp[i+ 1][j + 1][k][1], dp[i][j][k][1]);
          }

          if(j - 1 < n) {
            if(vi[j - 1] == -1) {
              repmax(dp[i + 1][j - 1][k][0], dp[i][j][k][1]);
            }else
              repmax(dp[i+1][j-1][k][1], dp[i][j][k][1]);
          }
        }
      }

  int maxval = 0;
  for(int i = 0; i <= 2*n; i++)
    for(int j = 0; j < n; j++)
      for(int k = 0; k <= n; k++) 
        maxval = max({maxval, dp[i][j][k][0], dp[i][j][k][1]});

  cout<<count(vi.begin(), vi.end(), 1) - maxval<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 222408 KB Output is correct
2 Correct 86 ms 222288 KB Output is correct
3 Correct 91 ms 222520 KB Output is correct
4 Correct 109 ms 222292 KB Output is correct
5 Correct 82 ms 222288 KB Output is correct
6 Correct 84 ms 222496 KB Output is correct
7 Correct 90 ms 222288 KB Output is correct
8 Correct 86 ms 222452 KB Output is correct
9 Correct 85 ms 222288 KB Output is correct
10 Correct 88 ms 222380 KB Output is correct
11 Correct 102 ms 222292 KB Output is correct
12 Correct 93 ms 222268 KB Output is correct
13 Correct 88 ms 222292 KB Output is correct
14 Correct 83 ms 222292 KB Output is correct
15 Correct 100 ms 222288 KB Output is correct
16 Correct 78 ms 222292 KB Output is correct
17 Correct 88 ms 222288 KB Output is correct
18 Correct 87 ms 222288 KB Output is correct
19 Correct 88 ms 222288 KB Output is correct
20 Correct 87 ms 222292 KB Output is correct
21 Correct 78 ms 222296 KB Output is correct
22 Correct 86 ms 222288 KB Output is correct
23 Correct 88 ms 222332 KB Output is correct
24 Correct 88 ms 222292 KB Output is correct
25 Correct 87 ms 222800 KB Output is correct
26 Correct 83 ms 222292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 222408 KB Output is correct
2 Correct 86 ms 222288 KB Output is correct
3 Correct 91 ms 222520 KB Output is correct
4 Correct 109 ms 222292 KB Output is correct
5 Correct 82 ms 222288 KB Output is correct
6 Correct 84 ms 222496 KB Output is correct
7 Correct 90 ms 222288 KB Output is correct
8 Correct 86 ms 222452 KB Output is correct
9 Correct 85 ms 222288 KB Output is correct
10 Correct 88 ms 222380 KB Output is correct
11 Correct 102 ms 222292 KB Output is correct
12 Correct 93 ms 222268 KB Output is correct
13 Correct 88 ms 222292 KB Output is correct
14 Correct 83 ms 222292 KB Output is correct
15 Correct 100 ms 222288 KB Output is correct
16 Correct 78 ms 222292 KB Output is correct
17 Correct 88 ms 222288 KB Output is correct
18 Correct 87 ms 222288 KB Output is correct
19 Correct 88 ms 222288 KB Output is correct
20 Correct 87 ms 222292 KB Output is correct
21 Correct 78 ms 222296 KB Output is correct
22 Correct 86 ms 222288 KB Output is correct
23 Correct 88 ms 222332 KB Output is correct
24 Correct 88 ms 222292 KB Output is correct
25 Correct 87 ms 222800 KB Output is correct
26 Correct 83 ms 222292 KB Output is correct
27 Correct 250 ms 339024 KB Output is correct
28 Correct 352 ms 419468 KB Output is correct
29 Correct 320 ms 391196 KB Output is correct
30 Correct 265 ms 349008 KB Output is correct
31 Correct 353 ms 423488 KB Output is correct
32 Correct 202 ms 287824 KB Output is correct
33 Correct 334 ms 383488 KB Output is correct
34 Correct 264 ms 348956 KB Output is correct
35 Correct 385 ms 436220 KB Output is correct
36 Correct 364 ms 436248 KB Output is correct
37 Correct 379 ms 436308 KB Output is correct
38 Correct 353 ms 436304 KB Output is correct
39 Correct 358 ms 436444 KB Output is correct
40 Correct 403 ms 436304 KB Output is correct
41 Correct 354 ms 436304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 222408 KB Output is correct
2 Correct 86 ms 222288 KB Output is correct
3 Correct 91 ms 222520 KB Output is correct
4 Correct 109 ms 222292 KB Output is correct
5 Correct 82 ms 222288 KB Output is correct
6 Correct 84 ms 222496 KB Output is correct
7 Correct 90 ms 222288 KB Output is correct
8 Correct 86 ms 222452 KB Output is correct
9 Correct 85 ms 222288 KB Output is correct
10 Correct 88 ms 222380 KB Output is correct
11 Correct 102 ms 222292 KB Output is correct
12 Correct 93 ms 222268 KB Output is correct
13 Correct 88 ms 222292 KB Output is correct
14 Correct 83 ms 222292 KB Output is correct
15 Correct 100 ms 222288 KB Output is correct
16 Correct 78 ms 222292 KB Output is correct
17 Correct 88 ms 222288 KB Output is correct
18 Correct 87 ms 222288 KB Output is correct
19 Correct 88 ms 222288 KB Output is correct
20 Correct 87 ms 222292 KB Output is correct
21 Correct 78 ms 222296 KB Output is correct
22 Correct 86 ms 222288 KB Output is correct
23 Correct 88 ms 222332 KB Output is correct
24 Correct 88 ms 222292 KB Output is correct
25 Correct 87 ms 222800 KB Output is correct
26 Correct 83 ms 222292 KB Output is correct
27 Correct 250 ms 339024 KB Output is correct
28 Correct 352 ms 419468 KB Output is correct
29 Correct 320 ms 391196 KB Output is correct
30 Correct 265 ms 349008 KB Output is correct
31 Correct 353 ms 423488 KB Output is correct
32 Correct 202 ms 287824 KB Output is correct
33 Correct 334 ms 383488 KB Output is correct
34 Correct 264 ms 348956 KB Output is correct
35 Correct 385 ms 436220 KB Output is correct
36 Correct 364 ms 436248 KB Output is correct
37 Correct 379 ms 436308 KB Output is correct
38 Correct 353 ms 436304 KB Output is correct
39 Correct 358 ms 436444 KB Output is correct
40 Correct 403 ms 436304 KB Output is correct
41 Correct 354 ms 436304 KB Output is correct
42 Incorrect 172 ms 272644 KB Output isn't correct
43 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 222408 KB Output is correct
2 Correct 86 ms 222288 KB Output is correct
3 Correct 91 ms 222520 KB Output is correct
4 Correct 109 ms 222292 KB Output is correct
5 Correct 82 ms 222288 KB Output is correct
6 Correct 84 ms 222496 KB Output is correct
7 Correct 90 ms 222288 KB Output is correct
8 Correct 86 ms 222452 KB Output is correct
9 Correct 85 ms 222288 KB Output is correct
10 Correct 88 ms 222380 KB Output is correct
11 Correct 102 ms 222292 KB Output is correct
12 Correct 93 ms 222268 KB Output is correct
13 Correct 88 ms 222292 KB Output is correct
14 Correct 83 ms 222292 KB Output is correct
15 Correct 100 ms 222288 KB Output is correct
16 Correct 78 ms 222292 KB Output is correct
17 Correct 88 ms 222288 KB Output is correct
18 Correct 87 ms 222288 KB Output is correct
19 Correct 88 ms 222288 KB Output is correct
20 Correct 87 ms 222292 KB Output is correct
21 Correct 78 ms 222296 KB Output is correct
22 Correct 86 ms 222288 KB Output is correct
23 Correct 88 ms 222332 KB Output is correct
24 Correct 88 ms 222292 KB Output is correct
25 Correct 87 ms 222800 KB Output is correct
26 Correct 83 ms 222292 KB Output is correct
27 Correct 250 ms 339024 KB Output is correct
28 Correct 352 ms 419468 KB Output is correct
29 Correct 320 ms 391196 KB Output is correct
30 Correct 265 ms 349008 KB Output is correct
31 Correct 353 ms 423488 KB Output is correct
32 Correct 202 ms 287824 KB Output is correct
33 Correct 334 ms 383488 KB Output is correct
34 Correct 264 ms 348956 KB Output is correct
35 Correct 385 ms 436220 KB Output is correct
36 Correct 364 ms 436248 KB Output is correct
37 Correct 379 ms 436308 KB Output is correct
38 Correct 353 ms 436304 KB Output is correct
39 Correct 358 ms 436444 KB Output is correct
40 Correct 403 ms 436304 KB Output is correct
41 Correct 354 ms 436304 KB Output is correct
42 Incorrect 172 ms 272644 KB Output isn't correct
43 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 222408 KB Output is correct
2 Correct 86 ms 222288 KB Output is correct
3 Correct 91 ms 222520 KB Output is correct
4 Correct 109 ms 222292 KB Output is correct
5 Correct 82 ms 222288 KB Output is correct
6 Correct 84 ms 222496 KB Output is correct
7 Correct 90 ms 222288 KB Output is correct
8 Correct 86 ms 222452 KB Output is correct
9 Correct 85 ms 222288 KB Output is correct
10 Correct 88 ms 222380 KB Output is correct
11 Correct 102 ms 222292 KB Output is correct
12 Correct 93 ms 222268 KB Output is correct
13 Correct 88 ms 222292 KB Output is correct
14 Correct 83 ms 222292 KB Output is correct
15 Correct 100 ms 222288 KB Output is correct
16 Correct 78 ms 222292 KB Output is correct
17 Correct 88 ms 222288 KB Output is correct
18 Correct 87 ms 222288 KB Output is correct
19 Correct 88 ms 222288 KB Output is correct
20 Correct 87 ms 222292 KB Output is correct
21 Correct 78 ms 222296 KB Output is correct
22 Correct 86 ms 222288 KB Output is correct
23 Correct 88 ms 222332 KB Output is correct
24 Correct 88 ms 222292 KB Output is correct
25 Correct 87 ms 222800 KB Output is correct
26 Correct 83 ms 222292 KB Output is correct
27 Correct 250 ms 339024 KB Output is correct
28 Correct 352 ms 419468 KB Output is correct
29 Correct 320 ms 391196 KB Output is correct
30 Correct 265 ms 349008 KB Output is correct
31 Correct 353 ms 423488 KB Output is correct
32 Correct 202 ms 287824 KB Output is correct
33 Correct 334 ms 383488 KB Output is correct
34 Correct 264 ms 348956 KB Output is correct
35 Correct 385 ms 436220 KB Output is correct
36 Correct 364 ms 436248 KB Output is correct
37 Correct 379 ms 436308 KB Output is correct
38 Correct 353 ms 436304 KB Output is correct
39 Correct 358 ms 436444 KB Output is correct
40 Correct 403 ms 436304 KB Output is correct
41 Correct 354 ms 436304 KB Output is correct
42 Incorrect 172 ms 272644 KB Output isn't correct
43 Halted 0 ms 0 KB -