Submission #691892

# Submission time Handle Problem Language Result Execution time Memory
691892 2023-01-31T22:03:35 Z balthazar Bank (IZhO14_bank) C++14
0 / 100
2 ms 428 KB
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int a;
    int b;
    cin>>a>>b;
    vector<int>av(a);
    vector<int>bv(b);
    for(int i=0;i<a;i++){
        cin>>av[i];
    }
    for(int i =0;i<b;i++){
        cin>>bv[i];
    }
    
    vector<pair<int, int>> dp(1<<b,{-1,0});
    dp[0]={0,0};
    for(int s=1;s<(1<<b);s++){
        for(int i = 0;i<b;i++){
            if(s>>i&1){
                auto prev = dp[s^(1<<i)];
                int valide = prev.first;
                int rest = prev.second;
                if(valide == -1)continue;
                if(rest + bv[i]==av[valide]){
                dp[s].first=valide+1;
                dp[s].second=0;
                }
                if(rest+bv[i]<av[valide] && dp[s].first <= valide){
                    
                    dp[s].first=valide;
                    dp[s].second=rest+bv[i];
                }
                
                
                if(dp[s].first == a){
                    cout<<"YES";
                    return 0;
                }
                
            }
        }
    }
    cout<<"N0";
    
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 428 KB Output is correct
3 Correct 1 ms 428 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -