Submission #1058079

#TimeUsernameProblemLanguageResultExecution timeMemory
1058079vjudge1Bank (IZhO14_bank)C++17
0 / 100
24 ms2652 KiB
#include<bits/stdc++.h>
#define ll long long
#define ii pair < int , int >
#define iii pair < int , ii>
#define iv pair < ii , ii >
#define fi first
#define se second
using namespace std;
const int N = 23;
const int mod = 1e9 + 7;
const int tt = 1e6;
const int base = 311;

int n, m;
int a[N], b[N], s[1 << N], presum[N], d[1 << N];
bool dp[1 << N];

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> m;
    for(int i = 1; i <= n; i++) cin >> a[i], presum[i] = presum[i - 1] + a[i];
    for(int j = 0; j < m; j++) cin >> b[j];
    for(int mask = 0; mask < (1 << m); mask++)
    {
        int sum = 0;
        for(int j = 0; j < m; j++)
            if((mask >> j) & 1)
                sum += b[j];
        s[mask] = sum;
    }
    int cur = 0;
    dp[0] = 1;
    d[0] = 0;
    for(int mask = 1; mask < (1 << m); mask++){
        int check = 0;
        for(int j = 0; j < m; j++) 
            if((mask >> j) & 1 && dp[mask ^ (1 << j)] == 1 && d[mask ^ (1 << j)] == cur)
                check = 1;
        if(check){
            dp[mask] = 1;
            if(s[mask] == presum[cur + 1]) cur++;
            d[mask] = cur;
            // cout << s[mask] << " " << presum[cur + 1] << endl;
        }
        cout << mask << " " << dp[mask] << " " << d[mask] << endl;
    }
    // cout << cur << endl;
    if(cur == n) cout << "YES";
    else cout << "NO";
}

Compilation message (stderr)

bank.cpp:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   18 | main()
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...