답안 #959788

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
959788 2024-04-09T05:31:48 Z ReLice Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
54 ms 66400 KB
#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
#define pll vector<pair<ll,ll>>
using namespace std;/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>*/
template<class S,class T>
bool chmin(S &a,const T &b) {
	return a>b?(a=b)==b:false;
}
template<class S,class T>
bool chmax(S &a,const T &b) {
	return a<b?(a=b)==b:false;
}
void start(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const ll inf=1e18+5;
const ll mod=1e9+7;
const ld eps=1e-9;
const ll N=2e2+5;
const ll M=1e6+5;
ll dp[N][N][N];
ll x[N],t[N];
ll n,l;
ll dis(ll i,ll j){
    return min(abs(x[i]-x[j]),min(x[i],x[j])+l-max(x[i],x[j]));
}
void solve(){
    ll i,j;
    cin>>n>>l;
    for(i=1;i<=n;i++) cin>>x[i];
    for(i=1;i<=n;i++) cin>>t[i];
    for(i=0;i<=n;i++){
        for(j=0;j<=n;j++){
            for(ll q=0;q<=n;q++)dp[i][j][q]=inf;
        }
    }
    if(dis(0,1)<=t[1]) dp[1][n][1]=dis(0,1);
    else dp[1][n][0]=dis(0,1);
    if(dis(0,n)<=t[n]) dp[n][1][1]=dis(0,n);
    else dp[n][1][0]=dis(0,n);
    ll ans=0;
    for(ll len=n-1;len>=0;len--){
        for(ll q=0;q<=n;q++){
            for(ll x=1;x+len<=n;x++){
                i=x,j=x+len;
                if(dp[i][j][q]<inf){
                    chmax(ans,q);
                    if(dis(i,j)<=t[j]-dp[i][j][q]) chmin(dp[j][i+1][q+1],dp[i][j][q]+dis(i,j));
                    else chmin(dp[j][i+1][q],dp[i][j][q]+dis(i,j));
                    if(dis(i,i+1)<=t[i+1]-dp[i][j][q]) chmin(dp[i+1][j][q+1],dp[i][j][q]+dis(i,i+1));
                    else chmin(dp[i+1][j][q],dp[i][j][q]+dis(i,i+1));
                }
                swap(i,j);
                if(dp[i][j][q]<inf){
                    chmax(ans,q);
                    if(dis(i,j)<=t[j]-dp[i][j][q]) chmin(dp[j][i-1][q+1],dp[i][j][q]+dis(i,j));
                    else chmin(dp[j][i-1][q],dp[i][j][q]+dis(i,j));
                    if(dis(i,i-1)<=t[i-1]-dp[i][j][q]) chmin(dp[i-1][j][q+1],dp[i][j][q]+dis(i,i-1));
                    else chmin(dp[i-1][j][q],dp[i][j][q]+dis(i,i-1));
                }
            }
        }
    }
    cout<<ans<<endl;
}
signed main(){
	start();
    ll t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}
/*




*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 2 ms 4584 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 2 ms 4584 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 6636 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6608 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4564 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6488 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6488 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 2 ms 4584 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 37 ms 59992 KB Output is correct
19 Correct 17 ms 47704 KB Output is correct
20 Correct 9 ms 35420 KB Output is correct
21 Correct 15 ms 45656 KB Output is correct
22 Correct 20 ms 51804 KB Output is correct
23 Correct 8 ms 31324 KB Output is correct
24 Correct 5 ms 29272 KB Output is correct
25 Correct 8 ms 31324 KB Output is correct
26 Correct 3 ms 18780 KB Output is correct
27 Correct 8 ms 33372 KB Output is correct
28 Correct 7 ms 27088 KB Output is correct
29 Correct 8 ms 33372 KB Output is correct
30 Correct 7 ms 29276 KB Output is correct
31 Correct 8 ms 31324 KB Output is correct
32 Correct 4 ms 23132 KB Output is correct
33 Correct 7 ms 31364 KB Output is correct
34 Correct 3 ms 18780 KB Output is correct
35 Correct 7 ms 31324 KB Output is correct
36 Correct 4 ms 21084 KB Output is correct
37 Correct 6 ms 33396 KB Output is correct
38 Correct 5 ms 25180 KB Output is correct
39 Correct 6 ms 33372 KB Output is correct
40 Correct 4 ms 25180 KB Output is correct
41 Correct 40 ms 66308 KB Output is correct
42 Correct 15 ms 55900 KB Output is correct
43 Correct 41 ms 66400 KB Output is correct
44 Correct 14 ms 55904 KB Output is correct
45 Correct 36 ms 66144 KB Output is correct
46 Correct 14 ms 55904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 2 ms 4584 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 6636 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6608 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4564 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6488 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6488 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 1 ms 6492 KB Output is correct
36 Correct 37 ms 59992 KB Output is correct
37 Correct 17 ms 47704 KB Output is correct
38 Correct 9 ms 35420 KB Output is correct
39 Correct 15 ms 45656 KB Output is correct
40 Correct 20 ms 51804 KB Output is correct
41 Correct 8 ms 31324 KB Output is correct
42 Correct 5 ms 29272 KB Output is correct
43 Correct 8 ms 31324 KB Output is correct
44 Correct 3 ms 18780 KB Output is correct
45 Correct 8 ms 33372 KB Output is correct
46 Correct 7 ms 27088 KB Output is correct
47 Correct 8 ms 33372 KB Output is correct
48 Correct 7 ms 29276 KB Output is correct
49 Correct 8 ms 31324 KB Output is correct
50 Correct 4 ms 23132 KB Output is correct
51 Correct 7 ms 31364 KB Output is correct
52 Correct 3 ms 18780 KB Output is correct
53 Correct 7 ms 31324 KB Output is correct
54 Correct 4 ms 21084 KB Output is correct
55 Correct 6 ms 33396 KB Output is correct
56 Correct 5 ms 25180 KB Output is correct
57 Correct 6 ms 33372 KB Output is correct
58 Correct 4 ms 25180 KB Output is correct
59 Correct 40 ms 66308 KB Output is correct
60 Correct 15 ms 55900 KB Output is correct
61 Correct 41 ms 66400 KB Output is correct
62 Correct 14 ms 55904 KB Output is correct
63 Correct 36 ms 66144 KB Output is correct
64 Correct 14 ms 55904 KB Output is correct
65 Correct 32 ms 64092 KB Output is correct
66 Correct 29 ms 62044 KB Output is correct
67 Correct 28 ms 60000 KB Output is correct
68 Correct 23 ms 57948 KB Output is correct
69 Correct 33 ms 64092 KB Output is correct
70 Correct 31 ms 62052 KB Output is correct
71 Correct 26 ms 62044 KB Output is correct
72 Correct 33 ms 62052 KB Output is correct
73 Correct 21 ms 60004 KB Output is correct
74 Correct 28 ms 58096 KB Output is correct
75 Correct 26 ms 62052 KB Output is correct
76 Correct 54 ms 66392 KB Output is correct
77 Correct 31 ms 66136 KB Output is correct
78 Correct 34 ms 57948 KB Output is correct
79 Correct 26 ms 57948 KB Output is correct
80 Correct 46 ms 66136 KB Output is correct
81 Correct 24 ms 59992 KB Output is correct
82 Correct 24 ms 59996 KB Output is correct
83 Correct 33 ms 66140 KB Output is correct
84 Correct 24 ms 62044 KB Output is correct
85 Correct 26 ms 64092 KB Output is correct
86 Correct 26 ms 64092 KB Output is correct
87 Correct 29 ms 62040 KB Output is correct
88 Correct 44 ms 66392 KB Output is correct
89 Correct 37 ms 66396 KB Output is correct
90 Correct 18 ms 62208 KB Output is correct
91 Correct 49 ms 66396 KB Output is correct
92 Correct 37 ms 66396 KB Output is correct
93 Correct 21 ms 66140 KB Output is correct