답안 #628531

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
628531 2022-08-13T13:04:57 Z Abrar_Al_Samit Collecting Stamps 3 (JOI20_ho_t3) C++17
15 / 100
260 ms 33088 KB
#include<bits/stdc++.h>
using namespace std;

const int MX = 203;
const int INF = 2e9;

int n, L;
int pos[MX], T[MX];
int dp[MX][MX][MX];

int dist(int i, int j) {
  int ret = abs(pos[i]-pos[j]);
  return min(ret, L-ret);
}
int solve(int i, int j, int k) {
  if(k==0) return dist(0, i);
  if(n-(abs(j-i)-1)<k) return INF;
  int &ret = dp[i][j][k];
  if(ret!=-1) return ret;

  ret = INF;
  if(i<=j) {
    if(i>1) {
      if(solve(i-1, j, k-1)+dist(i, i-1)<=T[i]) {
        ret = min(ret, solve(i-1, j, k-1)+dist(i, i-1));
      }
      if(solve(i-1, j, k)!=INF) {
        ret = min(ret, solve(i-1, j, k)+dist(i, i-1));
      }
    } else {
      if(j==n && dist(0, i)<=T[i] && k==1) {
        ret = min(ret, dist(0, i));
      } 
    }
    if(j+1<=n) {
      if(solve(j+1, i, k-1)+dist(j+1, i)<=T[i]) {
        ret = min(ret, solve(j+1, i, k-1)+dist(j+1, i));
      }
      if(solve(j+1, i, k)!=INF) {
        ret = min(ret, solve(j+1, i, k)+dist(j+1, i));
      }
    }
  } else {
    if(i+1<=n) {
      if(solve(i+1, j, k-1)+dist(i, i+1)<=T[i]) {
        ret = min(ret, solve(i+1, j, k-1)+dist(i, i+1));
      }
      if(solve(i+1, j, k)!=INF) {
        ret = min(ret, solve(i+1, j, k)+dist(i, i+1));
      }
    }
    if(j>1) {
      if(solve(j-1, i, k-1)+dist(i, j-1)<=T[i]) {
        ret = min(ret, solve(j-1, i, k-1)+dist(i, j-1));
      }
      if(solve(j-1, i, k)!=INF) {
        ret = min(ret, solve(j-1, i, k)+dist(i, j-1));
      }
    } else {
      if(i==n && dist(0, i)<=T[i] && k==1) {
        ret = min(ret, dist(0, i));
      }
    }
  }
  return ret;
}
void PlayGround() {
  cin>>n>>L;
  for(int i=1; i<=n; ++i) {
    cin>>pos[i];
  }
  for(int i=1; i<=n; ++i) {
    cin>>T[i];
  }

  memset(dp, -1, sizeof dp);
  int ans = 0;
  for(int i=1; i<=n; ++i) {
    for(int j=1; j<=n; ++j) {
      for(int k=1; k<=n; ++k) {
        if(solve(i, j, k)<INF) {
          ans = max(ans, k);
        }
      }
    }
  }
  cout<<ans<<'\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  PlayGround();
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 32980 KB Output is correct
2 Correct 16 ms 32980 KB Output is correct
3 Correct 14 ms 32980 KB Output is correct
4 Correct 15 ms 32964 KB Output is correct
5 Correct 17 ms 32988 KB Output is correct
6 Correct 14 ms 32980 KB Output is correct
7 Correct 14 ms 33032 KB Output is correct
8 Correct 17 ms 32984 KB Output is correct
9 Correct 14 ms 32980 KB Output is correct
10 Correct 13 ms 32988 KB Output is correct
11 Correct 13 ms 32980 KB Output is correct
12 Correct 14 ms 33028 KB Output is correct
13 Correct 14 ms 32980 KB Output is correct
14 Correct 13 ms 32980 KB Output is correct
15 Correct 13 ms 32980 KB Output is correct
16 Correct 14 ms 32980 KB Output is correct
17 Correct 14 ms 32980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 32980 KB Output is correct
2 Correct 16 ms 32980 KB Output is correct
3 Correct 14 ms 32980 KB Output is correct
4 Correct 15 ms 32964 KB Output is correct
5 Correct 17 ms 32988 KB Output is correct
6 Correct 14 ms 32980 KB Output is correct
7 Correct 14 ms 33032 KB Output is correct
8 Correct 17 ms 32984 KB Output is correct
9 Correct 14 ms 32980 KB Output is correct
10 Correct 13 ms 32988 KB Output is correct
11 Correct 13 ms 32980 KB Output is correct
12 Correct 14 ms 33028 KB Output is correct
13 Correct 14 ms 32980 KB Output is correct
14 Correct 13 ms 32980 KB Output is correct
15 Correct 13 ms 32980 KB Output is correct
16 Correct 14 ms 32980 KB Output is correct
17 Correct 14 ms 32980 KB Output is correct
18 Incorrect 15 ms 32952 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 32980 KB Output is correct
2 Correct 16 ms 32980 KB Output is correct
3 Correct 14 ms 32980 KB Output is correct
4 Correct 15 ms 32964 KB Output is correct
5 Correct 17 ms 32988 KB Output is correct
6 Correct 14 ms 32980 KB Output is correct
7 Correct 14 ms 33032 KB Output is correct
8 Correct 17 ms 32984 KB Output is correct
9 Correct 14 ms 32980 KB Output is correct
10 Correct 13 ms 32988 KB Output is correct
11 Correct 13 ms 32980 KB Output is correct
12 Correct 14 ms 33028 KB Output is correct
13 Correct 14 ms 32980 KB Output is correct
14 Correct 13 ms 32980 KB Output is correct
15 Correct 13 ms 32980 KB Output is correct
16 Correct 14 ms 32980 KB Output is correct
17 Correct 14 ms 32980 KB Output is correct
18 Correct 168 ms 33060 KB Output is correct
19 Correct 98 ms 33056 KB Output is correct
20 Correct 42 ms 32980 KB Output is correct
21 Correct 88 ms 33052 KB Output is correct
22 Correct 115 ms 33056 KB Output is correct
23 Correct 42 ms 32980 KB Output is correct
24 Correct 32 ms 32976 KB Output is correct
25 Correct 40 ms 32968 KB Output is correct
26 Correct 18 ms 32980 KB Output is correct
27 Correct 46 ms 33052 KB Output is correct
28 Correct 26 ms 32968 KB Output is correct
29 Correct 40 ms 32948 KB Output is correct
30 Correct 27 ms 32992 KB Output is correct
31 Correct 37 ms 33064 KB Output is correct
32 Correct 20 ms 32944 KB Output is correct
33 Correct 38 ms 33048 KB Output is correct
34 Correct 17 ms 32980 KB Output is correct
35 Correct 45 ms 33060 KB Output is correct
36 Correct 25 ms 32980 KB Output is correct
37 Correct 32 ms 33068 KB Output is correct
38 Correct 22 ms 33064 KB Output is correct
39 Correct 47 ms 32980 KB Output is correct
40 Correct 22 ms 32952 KB Output is correct
41 Correct 248 ms 33016 KB Output is correct
42 Correct 103 ms 33064 KB Output is correct
43 Correct 260 ms 33072 KB Output is correct
44 Correct 89 ms 33064 KB Output is correct
45 Correct 247 ms 33088 KB Output is correct
46 Correct 95 ms 33016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 32980 KB Output is correct
2 Correct 16 ms 32980 KB Output is correct
3 Correct 14 ms 32980 KB Output is correct
4 Correct 15 ms 32964 KB Output is correct
5 Correct 17 ms 32988 KB Output is correct
6 Correct 14 ms 32980 KB Output is correct
7 Correct 14 ms 33032 KB Output is correct
8 Correct 17 ms 32984 KB Output is correct
9 Correct 14 ms 32980 KB Output is correct
10 Correct 13 ms 32988 KB Output is correct
11 Correct 13 ms 32980 KB Output is correct
12 Correct 14 ms 33028 KB Output is correct
13 Correct 14 ms 32980 KB Output is correct
14 Correct 13 ms 32980 KB Output is correct
15 Correct 13 ms 32980 KB Output is correct
16 Correct 14 ms 32980 KB Output is correct
17 Correct 14 ms 32980 KB Output is correct
18 Incorrect 15 ms 32952 KB Output isn't correct
19 Halted 0 ms 0 KB -