답안 #874444

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
874444 2023-11-17T04:04:11 Z Maite_Morale Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
174 ms 222060 KB
#include<bits/stdc++.h>
#define F first
#define S second
#define MAX 205
#define oo 1e18
#define mod 1000000007
#define fast_in ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout.setf(ios::fixed);cout.precision(0);
using namespace std;
typedef long long ll;
#define pll pair<ll , ll>
#define vll vector<ll>
#define vvll vector<vll>
#define vpll vector<pll>

ll dp[MAX][410][MAX][5],a[410],t[410],n,m;   
int main(){
    fast_in
    cin>>n>>m;a[n]=m;t[n]=0;
    for(int i=0;i<n;i++){
        cin>>a[i];a[i+n+1]=a[i]+m;
    }
    for(int i=0;i<n;i++){
        cin>>t[i];t[i+n+1]=t[i];
    }
    for(int k=0;k<=n;k++)
        for(int i=n;i>=0;i--)
            for(int j=n;j<=i+n;j++)
                dp[i][j][k][0]=dp[i][j][k][1]=-1;
    dp[n][n][0][0]=dp[n][n][0][1]=0;
    ll r=0;
    for(int k=0;k<=n;k++){
        for(int i=n;i>=0;i--){
            for(int j=n;j<=i+n;j++){
                if(dp[i][j][k][0]!=-1){
                    if(j<i+n){
                        ll x=0,y=dp[i][j][k][0]+abs(a[i]-a[j+1]);
                        if(y<=t[j+1])x++;
                        if(dp[i][j+1][k+x][1]==-1)dp[i][j+1][k+x][1]=y;
                        else dp[i][j+1][k+x][1]=min(dp[i][j+1][k+x][1],y);
                    }
                    if(i>0){
                        ll x=0,y=dp[i][j][k][0]+abs(a[i]-a[i-1]);
                        if(y<=t[i-1])x++;
                        if(dp[i-1][j][k+x][0]==-1)dp[i-1][j][k+x][0]=y;
                        else dp[i-1][j][k+x][0]=min(dp[i-1][j][k+x][0],y);
                    }
                }
                if(dp[i][j][k][1]!=-1){
                    if(j<i+n){
                        ll x=0,y=dp[i][j][k][1]+abs(a[j]-a[j+1]);
                        if(y<=t[j+1])x++;
                        if(dp[i][j+1][k+x][1]==-1)dp[i][j+1][k+x][1]=y;
                        else   dp[i][j+1][k+x][1]=min(dp[i][j+1][k+x][1],y);
                    }
                    if(i>0){
                        ll x=0,y=dp[i][j][k][1]+abs(a[j]-a[i-1]);
                        if(y<=t[i-1])x++;
                        if(dp[i-1][j][k+x][0]==-1)dp[i-1][j][k+x][0]=y;
                        else dp[i-1][j][k+x][0]=min(dp[i-1][j][k+x][0],y);
                    }
                }
                if(dp[i][j][k][1]!=-1 || dp[i][j][k][0]!=-1)r=k;
            }
        }
    }cout<<r<<" ";
return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 2 ms 18780 KB Output is correct
4 Correct 1 ms 12636 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 3 ms 27100 KB Output is correct
7 Correct 2 ms 16732 KB Output is correct
8 Correct 3 ms 22876 KB Output is correct
9 Correct 3 ms 27132 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 3 ms 26972 KB Output is correct
13 Correct 3 ms 26972 KB Output is correct
14 Correct 2 ms 14684 KB Output is correct
15 Correct 2 ms 16732 KB Output is correct
16 Correct 3 ms 26972 KB Output is correct
17 Correct 3 ms 26972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 2 ms 18780 KB Output is correct
4 Correct 1 ms 12636 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 3 ms 27100 KB Output is correct
7 Correct 2 ms 16732 KB Output is correct
8 Correct 3 ms 22876 KB Output is correct
9 Correct 3 ms 27132 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 3 ms 26972 KB Output is correct
13 Correct 3 ms 26972 KB Output is correct
14 Correct 2 ms 14684 KB Output is correct
15 Correct 2 ms 16732 KB Output is correct
16 Correct 3 ms 26972 KB Output is correct
17 Correct 3 ms 26972 KB Output is correct
18 Correct 3 ms 31064 KB Output is correct
19 Correct 2 ms 22876 KB Output is correct
20 Correct 3 ms 26972 KB Output is correct
21 Correct 3 ms 31188 KB Output is correct
22 Correct 2 ms 18776 KB Output is correct
23 Correct 4 ms 33276 KB Output is correct
24 Correct 3 ms 31232 KB Output is correct
25 Correct 3 ms 31068 KB Output is correct
26 Correct 3 ms 31064 KB Output is correct
27 Correct 3 ms 16732 KB Output is correct
28 Correct 2 ms 19032 KB Output is correct
29 Correct 5 ms 33284 KB Output is correct
30 Correct 4 ms 33284 KB Output is correct
31 Correct 4 ms 31068 KB Output is correct
32 Correct 4 ms 31228 KB Output is correct
33 Correct 5 ms 33116 KB Output is correct
34 Correct 4 ms 33116 KB Output is correct
35 Correct 4 ms 33116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 2 ms 18780 KB Output is correct
4 Correct 1 ms 12636 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 3 ms 27100 KB Output is correct
7 Correct 2 ms 16732 KB Output is correct
8 Correct 3 ms 22876 KB Output is correct
9 Correct 3 ms 27132 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 3 ms 26972 KB Output is correct
13 Correct 3 ms 26972 KB Output is correct
14 Correct 2 ms 14684 KB Output is correct
15 Correct 2 ms 16732 KB Output is correct
16 Correct 3 ms 26972 KB Output is correct
17 Correct 3 ms 26972 KB Output is correct
18 Correct 123 ms 192340 KB Output is correct
19 Correct 62 ms 149080 KB Output is correct
20 Correct 30 ms 120472 KB Output is correct
21 Correct 56 ms 146260 KB Output is correct
22 Correct 79 ms 165912 KB Output is correct
23 Correct 25 ms 115028 KB Output is correct
24 Correct 18 ms 109916 KB Output is correct
25 Correct 24 ms 114772 KB Output is correct
26 Correct 12 ms 103772 KB Output is correct
27 Correct 26 ms 115940 KB Output is correct
28 Correct 17 ms 109148 KB Output is correct
29 Correct 27 ms 116364 KB Output is correct
30 Correct 19 ms 112476 KB Output is correct
31 Correct 24 ms 114772 KB Output is correct
32 Correct 14 ms 105308 KB Output is correct
33 Correct 24 ms 114780 KB Output is correct
34 Correct 12 ms 103516 KB Output is correct
35 Correct 22 ms 115600 KB Output is correct
36 Correct 12 ms 104284 KB Output is correct
37 Correct 23 ms 115648 KB Output is correct
38 Correct 14 ms 106584 KB Output is correct
39 Correct 25 ms 118364 KB Output is correct
40 Correct 16 ms 107356 KB Output is correct
41 Correct 162 ms 220308 KB Output is correct
42 Correct 92 ms 173664 KB Output is correct
43 Correct 164 ms 220480 KB Output is correct
44 Correct 84 ms 173404 KB Output is correct
45 Correct 169 ms 220316 KB Output is correct
46 Correct 85 ms 173664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 2 ms 18780 KB Output is correct
4 Correct 1 ms 12636 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 3 ms 27100 KB Output is correct
7 Correct 2 ms 16732 KB Output is correct
8 Correct 3 ms 22876 KB Output is correct
9 Correct 3 ms 27132 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 3 ms 26972 KB Output is correct
13 Correct 3 ms 26972 KB Output is correct
14 Correct 2 ms 14684 KB Output is correct
15 Correct 2 ms 16732 KB Output is correct
16 Correct 3 ms 26972 KB Output is correct
17 Correct 3 ms 26972 KB Output is correct
18 Correct 3 ms 31064 KB Output is correct
19 Correct 2 ms 22876 KB Output is correct
20 Correct 3 ms 26972 KB Output is correct
21 Correct 3 ms 31188 KB Output is correct
22 Correct 2 ms 18776 KB Output is correct
23 Correct 4 ms 33276 KB Output is correct
24 Correct 3 ms 31232 KB Output is correct
25 Correct 3 ms 31068 KB Output is correct
26 Correct 3 ms 31064 KB Output is correct
27 Correct 3 ms 16732 KB Output is correct
28 Correct 2 ms 19032 KB Output is correct
29 Correct 5 ms 33284 KB Output is correct
30 Correct 4 ms 33284 KB Output is correct
31 Correct 4 ms 31068 KB Output is correct
32 Correct 4 ms 31228 KB Output is correct
33 Correct 5 ms 33116 KB Output is correct
34 Correct 4 ms 33116 KB Output is correct
35 Correct 4 ms 33116 KB Output is correct
36 Correct 123 ms 192340 KB Output is correct
37 Correct 62 ms 149080 KB Output is correct
38 Correct 30 ms 120472 KB Output is correct
39 Correct 56 ms 146260 KB Output is correct
40 Correct 79 ms 165912 KB Output is correct
41 Correct 25 ms 115028 KB Output is correct
42 Correct 18 ms 109916 KB Output is correct
43 Correct 24 ms 114772 KB Output is correct
44 Correct 12 ms 103772 KB Output is correct
45 Correct 26 ms 115940 KB Output is correct
46 Correct 17 ms 109148 KB Output is correct
47 Correct 27 ms 116364 KB Output is correct
48 Correct 19 ms 112476 KB Output is correct
49 Correct 24 ms 114772 KB Output is correct
50 Correct 14 ms 105308 KB Output is correct
51 Correct 24 ms 114780 KB Output is correct
52 Correct 12 ms 103516 KB Output is correct
53 Correct 22 ms 115600 KB Output is correct
54 Correct 12 ms 104284 KB Output is correct
55 Correct 23 ms 115648 KB Output is correct
56 Correct 14 ms 106584 KB Output is correct
57 Correct 25 ms 118364 KB Output is correct
58 Correct 16 ms 107356 KB Output is correct
59 Correct 162 ms 220308 KB Output is correct
60 Correct 92 ms 173664 KB Output is correct
61 Correct 164 ms 220480 KB Output is correct
62 Correct 84 ms 173404 KB Output is correct
63 Correct 169 ms 220316 KB Output is correct
64 Correct 85 ms 173664 KB Output is correct
65 Correct 146 ms 206776 KB Output is correct
66 Correct 129 ms 196828 KB Output is correct
67 Correct 114 ms 191780 KB Output is correct
68 Correct 115 ms 183384 KB Output is correct
69 Correct 137 ms 205496 KB Output is correct
70 Correct 139 ms 201052 KB Output is correct
71 Correct 130 ms 200540 KB Output is correct
72 Correct 146 ms 203344 KB Output is correct
73 Correct 115 ms 194132 KB Output is correct
74 Correct 119 ms 187524 KB Output is correct
75 Correct 138 ms 199288 KB Output is correct
76 Correct 156 ms 214864 KB Output is correct
77 Correct 155 ms 214536 KB Output is correct
78 Correct 111 ms 183896 KB Output is correct
79 Correct 111 ms 188240 KB Output is correct
80 Correct 154 ms 212420 KB Output is correct
81 Correct 113 ms 188244 KB Output is correct
82 Correct 118 ms 194360 KB Output is correct
83 Correct 165 ms 220048 KB Output is correct
84 Correct 120 ms 200276 KB Output is correct
85 Correct 145 ms 210540 KB Output is correct
86 Correct 137 ms 206932 KB Output is correct
87 Correct 125 ms 197984 KB Output is correct
88 Correct 174 ms 222036 KB Output is correct
89 Correct 174 ms 221888 KB Output is correct
90 Correct 119 ms 198792 KB Output is correct
91 Correct 170 ms 221760 KB Output is correct
92 Correct 170 ms 222060 KB Output is correct
93 Correct 136 ms 216916 KB Output is correct