Submission #723488

# Submission time Handle Problem Language Result Execution time Memory
723488 2023-04-13T23:29:02 Z PanosPask Bank (IZhO14_bank) C++14
0 / 100
4 ms 8404 KB
#include <bits/stdc++.h>
#define MAXN 20
#define CHECK_BIT(var, pos) (var & (1<<pos))

using namespace std;

int n, m;

// dp[i]: The maximum prefix of people we can pay with the subset i
int dp[(1<<MAXN)];
// leftorvers[i]: How much money is leftorvers after paying the dp[i] people
int leftorvers[(1<<MAXN)];

int reqs[MAXN + 2];
int notes[MAXN + 2];

int main(void)
{
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++)
        scanf("%d", &reqs[i]);
    for (int i = 0; i < m; i++)
        scanf("%d", &notes[i]);

    memset(dp, -1, sizeof(dp));
    memset(leftorvers, -1, sizeof(leftorvers));
    dp[0] = 0;
    leftorvers[0] = 0;

    for (int s = 0; s < (1<<m); s++) {
        if (dp[s] == -1) 
            continue;
        if (dp[s] == n) {
            printf("YES\n");
            return 0;
        }

        int to_cover = reqs[dp[s]];
        for (int i = 0; i < m; i++) {
            if (CHECK_BIT(s, i))
                continue;
            
            // Use i as the last banknote
            int val = notes[i];
            if (val + leftorvers[s] < to_cover) {
                dp[s + (1<<i)] = dp[s];
                leftorvers[s + (1<<i)] = leftorvers[s] + to_cover;
            }
            else if (val + leftorvers[s] == to_cover) {
                dp[s + (1<<i)] = dp[s] + 1;
                leftorvers[s + (1<<i)] = 0;
            }
        }
    }

    printf("NO\n");
    return 0;
}

Compilation message

bank.cpp: In function 'int main()':
bank.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
bank.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         scanf("%d", &reqs[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~
bank.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         scanf("%d", &notes[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 8404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 8404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 8404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 8404 KB Output isn't correct
2 Halted 0 ms 0 KB -