답안 #702223

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
702223 2023-02-23T10:32:19 Z huomark1001 Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
138 ms 195596 KB
#include<bits/stdc++.h>
#include<random>
 
using namespace std;
 
template<typename T> void _do(T x){cerr<<x<<"\n";}
template<typename T,typename ...U> void _do(T x,U ...y){cerr<<x<<", ";_do(y...);}
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);
 
#define ss(n) fixed<<setprecision(n)
#define ll long long
#define int ll
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define rep(i,a) for(int i=1;i<=a;i++)
#define rep0(i,a) for(int i=0;i<a;i++)
#define F first
#define S second
#define float double
 
ll gcd(ll a,ll b){if(b==0) return a; return gcd(b,a%b);}
 
const ld pi=3.14159265358979323846264338327950288419716939931;
const int lar=3e18;
const int mol1=1e9+7;
const int mol2=998224353;
const int mol3=1e15+9;
const int bb=137;
int dp[205][205][205][3];
void solve()
{
    int n,l;
    cin>>n>>l;
    int d[n+1]={0},t[n+1]={0},pd[n+1]={0},pt[n+1]={0};
    rep(i,n) cin>>d[i];
    rep(i,n) cin>>t[i];
    for(int i=1;i<=n;i++){
        pd[i]=l-d[n+1-i];
        pt[i]=t[n+1-i];
    }
    
    d[0]=0,t[0]=0;
    rep0(i,n+1) {
        rep0(j,n+1){
            rep0(k,n+1){
                dp[i][j][k][0]=lar+2;
                dp[i][j][k][1]=lar+2;
            }
        }
    }
    int ans=0;
    dp[0][0][0][0]=0;
    dp[0][0][0][1]=0;
    rep0(i,n+1){
        rep0(j,n+1){
            if(i+j>n-1) break;
            for(int k=0;k<=i+j;k++){
                if(dp[i][j][k][0]<lar){
                    dp[i][j+1][k+(dp[i][j][k][0]+d[j+1]-d[j]<=t[j+1])][0]=min(dp[i][j+1][k+(dp[i][j][k][0]+d[j+1]-d[j]<=t[j+1])][0],dp[i][j][k][0]+d[j+1]-d[j]);
                    dp[i+1][j][k+(dp[i][j][k][0]+pd[i+1]+d[j]<=pt[i+1])][1]=min(dp[i+1][j][k+(dp[i][j][k][0]+pd[i+1]+d[j]<=pt[i+1])][1],dp[i][j][k][0]+pd[i+1]+d[j]);
                    if(dp[i][j+1][k+(dp[i][j][k][0]+d[j+1]-d[j]<=t[j+1])][0]<lar) {
                        ans=max(ans,k+(dp[i][j][k][0]+d[j+1]-d[j]<=t[j+1]));
                    }
                    if(dp[i+1][j][k+(dp[i][j][k][0]+pd[i+1]+d[j]<=pt[i+1])][1]<lar) ans=max(ans,k+(dp[i][j][k][0]+pd[i+1]+d[j]<=pt[i+1]));
                
                }
                if(dp[i][j][k][1]<lar){
                    dp[i][j+1][k+(dp[i][j][k][1]+pd[i]+d[j+1]<=t[j+1])][0]=min(dp[i][j+1][k+(dp[i][j][k][1]+pd[i]+d[j+1]<=t[j+1])][0],dp[i][j][k][1]+pd[i]+d[j+1]);
                    dp[i+1][j][k+(dp[i][j][k][1]+pd[i+1]-pd[i]<=pt[i+1])][1]=min(dp[i+1][j][k+(dp[i][j][k][1]+pd[i+1]-pd[i]<=pt[i+1])][1],dp[i][j][k][1]+pd[i+1]-pd[i]);
                    if(dp[i][j+1][k+(dp[i][j][k][1]+pd[i]+d[j+1]<=t[j+1])][0]<lar) ans=max(ans,k+(dp[i][j][k][1]+pd[i]+d[j+1]<=t[j+1]));
                    if(dp[i+1][j][k+(dp[i][j][k][1]+pd[i+1]-pd[i]<=pt[i+1])][1]<lar) ans=max(ans,k+(dp[i][j][k][1]+pd[i+1]-pd[i]<=pt[i+1]));
                }
            }
        }
    }
    cout<<ans<<"\n";
}
 
signed main()
{
    IO
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 724 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 1000 KB Output is correct
10 Correct 1 ms 264 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 1060 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 724 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 1000 KB Output is correct
10 Correct 1 ms 264 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 1060 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 980 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 1364 KB Output is correct
24 Correct 1 ms 1108 KB Output is correct
25 Correct 1 ms 1236 KB Output is correct
26 Correct 1 ms 1236 KB Output is correct
27 Correct 0 ms 596 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
29 Correct 1 ms 1364 KB Output is correct
30 Correct 1 ms 1364 KB Output is correct
31 Correct 1 ms 1236 KB Output is correct
32 Correct 1 ms 1096 KB Output is correct
33 Correct 1 ms 1364 KB Output is correct
34 Correct 1 ms 1364 KB Output is correct
35 Correct 1 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 724 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 1000 KB Output is correct
10 Correct 1 ms 264 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 1060 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 91 ms 156916 KB Output is correct
19 Correct 54 ms 95168 KB Output is correct
20 Correct 25 ms 50628 KB Output is correct
21 Correct 48 ms 89660 KB Output is correct
22 Correct 66 ms 116436 KB Output is correct
23 Correct 29 ms 42984 KB Output is correct
24 Correct 19 ms 33612 KB Output is correct
25 Correct 23 ms 42124 KB Output is correct
26 Correct 8 ms 15956 KB Output is correct
27 Correct 25 ms 43980 KB Output is correct
28 Correct 15 ms 31304 KB Output is correct
29 Correct 24 ms 44920 KB Output is correct
30 Correct 17 ms 35284 KB Output is correct
31 Correct 22 ms 42068 KB Output is correct
32 Correct 11 ms 21960 KB Output is correct
33 Correct 24 ms 42124 KB Output is correct
34 Correct 7 ms 14924 KB Output is correct
35 Correct 19 ms 41172 KB Output is correct
36 Correct 9 ms 19540 KB Output is correct
37 Correct 20 ms 43988 KB Output is correct
38 Correct 13 ms 24148 KB Output is correct
39 Correct 21 ms 45768 KB Output is correct
40 Correct 13 ms 26836 KB Output is correct
41 Correct 127 ms 193652 KB Output is correct
42 Correct 56 ms 130228 KB Output is correct
43 Correct 126 ms 193556 KB Output is correct
44 Correct 69 ms 128724 KB Output is correct
45 Correct 131 ms 193684 KB Output is correct
46 Correct 57 ms 130308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 724 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 1000 KB Output is correct
10 Correct 1 ms 264 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 1060 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 980 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 1364 KB Output is correct
24 Correct 1 ms 1108 KB Output is correct
25 Correct 1 ms 1236 KB Output is correct
26 Correct 1 ms 1236 KB Output is correct
27 Correct 0 ms 596 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
29 Correct 1 ms 1364 KB Output is correct
30 Correct 1 ms 1364 KB Output is correct
31 Correct 1 ms 1236 KB Output is correct
32 Correct 1 ms 1096 KB Output is correct
33 Correct 1 ms 1364 KB Output is correct
34 Correct 1 ms 1364 KB Output is correct
35 Correct 1 ms 1364 KB Output is correct
36 Correct 91 ms 156916 KB Output is correct
37 Correct 54 ms 95168 KB Output is correct
38 Correct 25 ms 50628 KB Output is correct
39 Correct 48 ms 89660 KB Output is correct
40 Correct 66 ms 116436 KB Output is correct
41 Correct 29 ms 42984 KB Output is correct
42 Correct 19 ms 33612 KB Output is correct
43 Correct 23 ms 42124 KB Output is correct
44 Correct 8 ms 15956 KB Output is correct
45 Correct 25 ms 43980 KB Output is correct
46 Correct 15 ms 31304 KB Output is correct
47 Correct 24 ms 44920 KB Output is correct
48 Correct 17 ms 35284 KB Output is correct
49 Correct 22 ms 42068 KB Output is correct
50 Correct 11 ms 21960 KB Output is correct
51 Correct 24 ms 42124 KB Output is correct
52 Correct 7 ms 14924 KB Output is correct
53 Correct 19 ms 41172 KB Output is correct
54 Correct 9 ms 19540 KB Output is correct
55 Correct 20 ms 43988 KB Output is correct
56 Correct 13 ms 24148 KB Output is correct
57 Correct 21 ms 45768 KB Output is correct
58 Correct 13 ms 26836 KB Output is correct
59 Correct 127 ms 193652 KB Output is correct
60 Correct 56 ms 130228 KB Output is correct
61 Correct 126 ms 193556 KB Output is correct
62 Correct 69 ms 128724 KB Output is correct
63 Correct 131 ms 193684 KB Output is correct
64 Correct 57 ms 130308 KB Output is correct
65 Correct 116 ms 174796 KB Output is correct
66 Correct 98 ms 160392 KB Output is correct
67 Correct 101 ms 153540 KB Output is correct
68 Correct 93 ms 141660 KB Output is correct
69 Correct 107 ms 172956 KB Output is correct
70 Correct 112 ms 165752 KB Output is correct
71 Correct 99 ms 167440 KB Output is correct
72 Correct 117 ms 169348 KB Output is correct
73 Correct 86 ms 156880 KB Output is correct
74 Correct 94 ms 146688 KB Output is correct
75 Correct 95 ms 162080 KB Output is correct
76 Correct 129 ms 185920 KB Output is correct
77 Correct 123 ms 186028 KB Output is correct
78 Correct 90 ms 143216 KB Output is correct
79 Correct 91 ms 148372 KB Output is correct
80 Correct 119 ms 182324 KB Output is correct
81 Correct 94 ms 149968 KB Output is correct
82 Correct 90 ms 158760 KB Output is correct
83 Correct 123 ms 193612 KB Output is correct
84 Correct 88 ms 165744 KB Output is correct
85 Correct 97 ms 180264 KB Output is correct
86 Correct 97 ms 176656 KB Output is correct
87 Correct 104 ms 162288 KB Output is correct
88 Correct 136 ms 195472 KB Output is correct
89 Correct 121 ms 195596 KB Output is correct
90 Correct 81 ms 163948 KB Output is correct
91 Correct 138 ms 195528 KB Output is correct
92 Correct 129 ms 195592 KB Output is correct
93 Correct 87 ms 191724 KB Output is correct