답안 #996926

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
996926 2024-06-11T12:36:16 Z irmuun Collecting Stamps 3 (JOI20_ho_t3) C++17
15 / 100
521 ms 1048576 KB
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

//try
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n,L;
    cin>>n>>L;
    ll x[n+5],t[n+5];
    for(ll i=1;i<=n;i++){
        cin>>x[i];
    }
    for(ll i=1;i<=n;i++){
        cin>>t[i];
    }
    x[0]=0;
    function <ll(ll,ll)> dist=[&](ll a,ll b){
        return min(abs(x[a]-x[b]),L-abs(x[a]-x[b]));
    };
    ll dp[1<<n][n+5][n+5];
    for(ll i=0;i<(1<<n);i++){
        for(ll j=0;j<=n;j++){
            for(ll k=0;k<=n;k++){
                dp[i][j][k]=1e18;
            }
        }
    }
    dp[0][0][0]=0;
    for(ll s=0;s<(1<<n);s++){
        for(ll i=0;i<=n;i++){
            if(i==0||(s&(1<<(i-1)))){
                for(ll k=0;k<=n;k++){
                    if(dp[s][i][k]==1e18) continue;
                    for(ll j=0;j<n;j++){//next pos 0-indexed
                        if((s&(1<<j))==0){//currently not stamped j
                            chmin(dp[s|(1<<j)][j+1][k+(dp[s][i][k]+dist(i,j+1)<=t[j+1])],dp[s][i][k]+dist(i,j+1));
                        }
                    }
                }
            }
        }
    }
    ll ans=0;
    for(ll s=0;s<(1<<n);s++){
        for(ll i=0;i<=n;i++){
            for(ll k=0;k<=n;k++){
                if(dp[s][i][k]!=1e18){
                    ans=max(ans,k);
                }
            }
        }
    }
    cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 1272 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 14 ms 9724 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 3 ms 2140 KB Output is correct
9 Correct 15 ms 9716 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 16 ms 9716 KB Output is correct
13 Correct 15 ms 9564 KB Output is correct
14 Correct 0 ms 452 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 10 ms 9564 KB Output is correct
17 Correct 11 ms 9564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 1272 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 14 ms 9724 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 3 ms 2140 KB Output is correct
9 Correct 15 ms 9716 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 16 ms 9716 KB Output is correct
13 Correct 15 ms 9564 KB Output is correct
14 Correct 0 ms 452 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 10 ms 9564 KB Output is correct
17 Correct 11 ms 9564 KB Output is correct
18 Correct 91 ms 46720 KB Output is correct
19 Correct 3 ms 2136 KB Output is correct
20 Correct 14 ms 9716 KB Output is correct
21 Correct 87 ms 46684 KB Output is correct
22 Correct 2 ms 1116 KB Output is correct
23 Correct 182 ms 102816 KB Output is correct
24 Correct 31 ms 21084 KB Output is correct
25 Correct 89 ms 46672 KB Output is correct
26 Correct 85 ms 46708 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 222 ms 102868 KB Output is correct
30 Correct 214 ms 102908 KB Output is correct
31 Correct 59 ms 46680 KB Output is correct
32 Correct 21 ms 21080 KB Output is correct
33 Correct 124 ms 102928 KB Output is correct
34 Correct 170 ms 102992 KB Output is correct
35 Correct 152 ms 102972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 1272 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 14 ms 9724 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 3 ms 2140 KB Output is correct
9 Correct 15 ms 9716 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 16 ms 9716 KB Output is correct
13 Correct 15 ms 9564 KB Output is correct
14 Correct 0 ms 452 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 10 ms 9564 KB Output is correct
17 Correct 11 ms 9564 KB Output is correct
18 Runtime error 521 ms 1048576 KB Execution killed with signal 9
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 1272 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 14 ms 9724 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 3 ms 2140 KB Output is correct
9 Correct 15 ms 9716 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 16 ms 9716 KB Output is correct
13 Correct 15 ms 9564 KB Output is correct
14 Correct 0 ms 452 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 10 ms 9564 KB Output is correct
17 Correct 11 ms 9564 KB Output is correct
18 Correct 91 ms 46720 KB Output is correct
19 Correct 3 ms 2136 KB Output is correct
20 Correct 14 ms 9716 KB Output is correct
21 Correct 87 ms 46684 KB Output is correct
22 Correct 2 ms 1116 KB Output is correct
23 Correct 182 ms 102816 KB Output is correct
24 Correct 31 ms 21084 KB Output is correct
25 Correct 89 ms 46672 KB Output is correct
26 Correct 85 ms 46708 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 222 ms 102868 KB Output is correct
30 Correct 214 ms 102908 KB Output is correct
31 Correct 59 ms 46680 KB Output is correct
32 Correct 21 ms 21080 KB Output is correct
33 Correct 124 ms 102928 KB Output is correct
34 Correct 170 ms 102992 KB Output is correct
35 Correct 152 ms 102972 KB Output is correct
36 Runtime error 521 ms 1048576 KB Execution killed with signal 9
37 Halted 0 ms 0 KB -