Submission #676205

# Submission time Handle Problem Language Result Execution time Memory
676205 2022-12-29T20:27:36 Z vjudge1 Bank (IZhO14_bank) C++17
52 / 100
1000 ms 24920 KB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define piii pair<pii, int>
#define pllll pair<ll, ll>
#define pb push_back
#define all(v) v.begin(), v.end()
#define size(v) v.size()
#define INF 2e18
#define f first
#define s second

using namespace std;

void solve(){
    int n, m;
    cin >> n >> m;
    vector<ll>a(n + 1), b(m + 1);
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }for(int i = 1; i <= m; ++i){
        cin >> b[i];
    }
    vector<ll>List[n + 1];
    for(int mask = 1; mask < (1 << m); ++mask){
        ll Total = 0;
        for(int i = 0; i < m; ++i){
            if(mask & (1 << i)){
                Total += b[i + 1];
            }
        }
        for(int i = 0; i < n; ++i){
            if(Total == a[i + 1]){
                List[i + 1].pb(mask);
            }
        }
    }
    vector<vector<ll>>dp(n + 1, vector<ll>(1 << m, 0));
    for(int i = 1; i <= n; ++i){
        for(int mask = 0; mask < (1 << m); ++mask){
            dp[0][mask] = 1;
            for(int j = 0; j < size(List[i]); ++j){
                if((mask & List[i][j]) == List[i][j]){
                    dp[i][mask] = max(dp[i][mask], dp[i - 1][mask ^ List[i][j]]);
                }
            }
        }
    }
    if(dp[n][(1 << m) - 1] == 1){
        cout << "YES\n";
    }else{
        cout << "NO\n";
    }
}

int main(){

    int t;
    t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Compilation message

bank.cpp: In function 'void solve()':
bank.cpp:42:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |             for(int j = 0; j < size(List[i]); ++j){
      |                              ^
# Verdict Execution time Memory Grader output
1 Correct 1 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 Correct 8 ms 1072 KB Output is correct
5 Correct 65 ms 24872 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Execution timed out 1086 ms 24920 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1492 KB Output is correct
2 Correct 2 ms 852 KB Output is correct
3 Correct 3 ms 1876 KB Output is correct
4 Correct 4 ms 2344 KB Output is correct
5 Correct 4 ms 1876 KB Output is correct
6 Correct 2 ms 1236 KB Output is correct
7 Correct 2 ms 980 KB Output is correct
8 Correct 2 ms 852 KB Output is correct
9 Correct 2 ms 1584 KB Output is correct
10 Correct 2 ms 1576 KB Output is correct
11 Correct 3 ms 2388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 Correct 8 ms 1072 KB Output is correct
5 Correct 65 ms 24872 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Execution timed out 1086 ms 24920 KB Time limit exceeded
9 Halted 0 ms 0 KB -