답안 #391210

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
391210 2021-04-18T09:19:14 Z lukameladze Collecting Stamps 3 (JOI20_ho_t3) C++14
5 / 100
67 ms 106044 KB
# include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
using namespace std;
const int N=205;
long long  n,x[N],dp[N][N][N][2],t[N],le,ri,l,ans,ff,ff1;
long long go(long long x, long long xx) {
     if (x<xx) swap(x,xx);
     return min(x-xx,xx-x+l);
}
long long mn(long long a, long long b , long long c) {
     return(min(a,min(b,c)));
}
int main() {
     cin>>n>>l;
     for (int i=1; i<=n; i++) {
          cin>>x[i];
     }
     for (int i=1; i<=n; i++) {
          cin>>t[i];
     }
     for (int le=0; le<=n+1; le++) {
          for (int ri=0; ri<=n+1; ri++) {
               for (int cnt=0; cnt<=n+1; cnt++) {
                    dp[le][ri][cnt][0]=dp[le][ri][cnt][1]=1e9;
               }
          }
     }
     dp[0][0][0][0]=0;
     dp[0][0][0][1]=0;
     x[0]=l;
     for (int sz=1; sz<=n; sz++) {
          for (int ri=0; ri<=sz; ri++) {
               if (ri==sz) le=0; 
                    else le=n-(sz-ri)+1;
               ff=ff1=0;
               for (int cnt=0; cnt<=sz; cnt++) {
                    dp[le][ri][cnt][0]=mn(dp[le][ri][cnt][0],dp[(le+1)%(n+1)][ri][cnt][0]+go(x[(le+1)%(n+1)],x[le]),dp[(le+1)%(n+1)][ri][cnt][1]+go(x[ri], x[le]));
                    if (ri)
                    dp[le][ri][cnt][1]=mn(dp[le][ri][cnt][1],dp[le][ri-1][cnt][1]+go(x[ri-1], x[ri]),dp[le][ri-1][cnt][0]+go(x[le],x[ri]));
                  /* if (cnt<sz) {
                         if (dp[le][ri][cnt][0]<=t[le]) {
                              dp[le][ri][cnt+1][0]=min(dp[le][ri][cnt+1][0],dp[le][ri][cnt][0]);
                         }
                         if (dp[le][ri][cnt][1]<=t[ri] && !ff1) {
                              dp[le][ri][cnt+1][1]=min(dp[le][ri][cnt+1][1],dp[le][ri][cnt][1]);
                         }
                    }*/
                 //  if (cnt==5 && dp[le][ri][cnt][1]<1e9)cout<<le<<" "<<ri<<" "<<cnt<<" "<<dp[le][ri][cnt][1]<<endl;
                    if (dp[le][ri][cnt][0]<(long long)1e9 || dp[le][ri][cnt][1]<(long long)1e9) { ans=max(ans,(long long)cnt);}
               }
       //        if (sz==2 && le==6 && ri==1) cout<<dp[6][1][2][1]<<endl;
               for (int cnt=sz; cnt>=1; cnt--) {
                    if (dp[le][ri][cnt-1][1]<=t[ri] && !ff) {
                         ff=1;
                          
                         dp[le][ri][cnt][1]=min(dp[le][ri][cnt][1],dp[le][ri][cnt-1][1]);
                         //if (sz==2 && le==6 && ri==1 && cnt==2) 
                         // cout<<dp[le][ri][cnt][1]<<endl;
                    }
                    if (dp[le][ri][cnt-1][0]<=t[le] && !ff1) {
                         ff1=1;
                         dp[le][ri][cnt][0]=min(dp[le][ri][cnt][0],dp[le][ri][cnt-1][0]);
                    }
                    if (dp[le][ri][cnt][0]<(long long)1e9 || dp[le][ri][cnt][1]<(long long)1e9) { ans=max(ans,(long long)cnt);}
               }
          }
     }
     //cout<<dp[6][1][2][0]<<endl;
     cout<<ans<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 1 ms 420 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 944 KB Output is correct
7 Correct 1 ms 560 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 1 ms 940 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 972 KB Output is correct
13 Correct 1 ms 972 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 976 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 1 ms 420 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 944 KB Output is correct
7 Correct 1 ms 560 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 1 ms 940 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 972 KB Output is correct
13 Correct 1 ms 972 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 976 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 1 ms 1100 KB Output is correct
19 Correct 1 ms 716 KB Output is correct
20 Correct 1 ms 1076 KB Output is correct
21 Correct 1 ms 1100 KB Output is correct
22 Correct 1 ms 716 KB Output is correct
23 Incorrect 1 ms 1228 KB Output isn't correct
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 1 ms 420 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 944 KB Output is correct
7 Correct 1 ms 560 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 1 ms 940 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 972 KB Output is correct
13 Correct 1 ms 972 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 976 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 67 ms 106044 KB Output is correct
19 Correct 37 ms 64516 KB Output is correct
20 Correct 22 ms 34636 KB Output is correct
21 Correct 36 ms 60956 KB Output is correct
22 Correct 49 ms 78924 KB Output is correct
23 Correct 16 ms 29516 KB Output is correct
24 Correct 13 ms 23116 KB Output is correct
25 Correct 16 ms 28944 KB Output is correct
26 Correct 6 ms 11212 KB Output is correct
27 Correct 16 ms 30112 KB Output is correct
28 Correct 11 ms 21504 KB Output is correct
29 Incorrect 17 ms 30796 KB Output isn't correct
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 1 ms 420 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 944 KB Output is correct
7 Correct 1 ms 560 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 1 ms 940 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 972 KB Output is correct
13 Correct 1 ms 972 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 976 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 1 ms 1100 KB Output is correct
19 Correct 1 ms 716 KB Output is correct
20 Correct 1 ms 1076 KB Output is correct
21 Correct 1 ms 1100 KB Output is correct
22 Correct 1 ms 716 KB Output is correct
23 Incorrect 1 ms 1228 KB Output isn't correct
24 Halted 0 ms 0 KB -