Submission #328558

# Submission time Handle Problem Language Result Execution time Memory
328558 2020-11-17T05:36:42 Z Killer2501 Bank (IZhO14_bank) C++14
0 / 100
1 ms 364 KB
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define task "guard"

using namespace std;
const int N = 25;
const ll mod = 1e9 + 7;
ll n, m, t, k, a[N], tong, ans, u, v, b[N], pos[N], d[N], dp[(1<<21)][21];
priority_queue< ll, vector<ll>, greater<ll> > pq;
ll c[N];
struct dang
{
    ll lc, rc, val, num;
}st[N];

vector<ll> adj[N], kq;
vector<pll> w;
ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n & 1)total = (total * k) % mod;
        k = (k * k) % mod;
    }
    return total;
}
string s;
void sol()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)cin >> a[i];
    for(int i = 1; i <= m; i ++)cin >> b[i];
    sort(b+1, b+1+m);
    dp[0][0] = 1;
    for(int i = 0; i < n; i ++)
    {
        for(int j = 0; j < (1<<m); j ++)
        {
            if(dp[i][j] == 0)continue;
            t = j;
            k = a[i+1];
            for(int l = m-1; l >= 0; l --)
            {
                if((j >> l) & 1)continue;
                if(b[l+1] <= k)
                {
                    k -= b[l+1];
                    t = (t | (1<<l));
                }
            }
            if(k == 0)
            {
                dp[i+1][t] = 1;
                if(i+1 == n)
                {
                    cout << "YES";
                    return;
                }
            }
        }
    }
    cout << "NO";
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(fopen(task".in", "r"))
    {
        freopen(task".in", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}
/*
8
+3
+3
+3
+3


*/

Compilation message

bank.cpp: In function 'int main()':
bank.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   76 |         freopen(task".in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   77 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -