제출 #1307493

#제출 시각아이디문제언어결과실행 시간메모리
1307493msunBank (IZhO14_bank)C++20
0 / 100
2 ms572 KiB
#include <cstdio>
#include <cstring>

using namespace std;

#define MAXNM 20
// #define MAXNM 6

int A[MAXNM], B[MAXNM], dp[1 << MAXNM], partial[1 << MAXNM];

int
main ()
{
    // freopen ("test.in", "r", stdin);

    int N, M;
    scanf ("%d%d", &N, &M);

    for (int i = 0; i < N; ++i)
        scanf ("%d", &A[i]);

    for (int i = 0; i < M; ++i)
        scanf ("%d", &B[i]);

    const int maxs = 1 << M;

    for (int s = 1; s < maxs; ++s) {
        for (int x = 0; x < M; ++x) {
            if (!(s & (1 << x)))
                continue;

            int ssubx = s ^ (1 << x);

            if (dp[ssubx] < 0)
                continue;

            int targ = A[dp[ssubx]];
            int amt  = partial[ssubx] + B[x];

            // not enough
            if (amt < targ) {
                dp[s] = dp[ssubx];
                partial[s] += B[x];
            } else if (amt == targ) {
                dp[s]      = dp[ssubx] + 1;
                partial[s] = 0;
            }
        }

        if (dp[s] == N) {
            printf ("%d\n", s);
            puts ("YES");
            return 0;
        }
    }

    puts ("NO");

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

bank.cpp: In function 'int main()':
bank.cpp:17:11: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf ("%d%d", &N, &M);
      |     ~~~~~~^~~~~~~~~~~~~~~~
bank.cpp:20:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         scanf ("%d", &A[i]);
      |         ~~~~~~^~~~~~~~~~~~~
bank.cpp:23:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         scanf ("%d", &B[i]);
      |         ~~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...