답안 #973654

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973654 2024-05-02T09:03:03 Z Aiperiii Collecting Stamps 3 (JOI20_ho_t3) C++14
0 / 100
1 ms 604 KB
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
signed main(){
    ios_base::sync_with_stdio();
    cin.tie(0);cout.tie(0);
    int n,L;
    cin>>n>>L;
    vector <int> a(n),b(n);
    for(int i=0;i<n;i++)cin>>a[i];
    map <int,int> dp[(1<<n)][n];
    for(int i=0;i<n;i++){
        cin>>b[i];
        if(min(a[i],L-a[i])<b[i])dp[(1<<i)][i][min(a[i],L-a[i])]=1;
    }
    for(int i=0;i<(1<<n);i++){
        for(int j=0;j<n;j++){
            if((i&(1<<j))){
                int mask=i^(1<<j);
                for(int l=0;l<n;l++){
                    if((mask&(1<<l))){
                        for(auto x : dp[mask][l]){
                            int mn=min(abs(a[j]-a[l]),L-max(a[j],a[l])+min(a[j],a[l]));
                            if(x.ff+mn<=b[j])dp[i][j][x.ff+mn]=max(dp[i][j][x.ff+mn],x.ss+1);
                        }
                    }
                    
                }
            }
        }
    }
    int mx=0;
    for(int i=0;i<(1<<n);i++){
        for(int j=0;j<n;j++){
            for(auto x : dp[i][j])mx=max(mx,x.ss);
        }
    }
    cout<<mx<<"\n";
}
/*
4 10
3 6 2 9
 
8 35
3 7 1 5 10 2 11 6
 
 
 
6 25
3 4 7 17 21 23
11 7 17 10 8 10
 
5 20
4 5 8 13 17
18 23 17 7 10
 
 4 19
 3 7 12 14
 2 0 5 4
 
 10 87
 9 23 33 38 42 44 45 62 67 78
 15 91 7 27 31 53 12 91 89 46
*/



# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -