제출 #679330

#제출 시각아이디문제언어결과실행 시간메모리
679330vjudge1은행 (IZhO14_bank)C++11
19 / 100
142 ms1260 KiB
#include<iostream>
using namespace std;
int n,m,req[25],has[25];
bool dp[1100005],binrep[25];
int main () {
    scanf("%d%d",&n,&m);
    for(int i = 0; i < n; i++) {
        scanf("%d",&req[i]);
    }
    for(int i = 0; i < m; i++) {
        scanf("%d",&has[i]);
    }
    dp[0] = true;
    for(int i = 0; i < (1<<m)-1; i++) {
        if(dp[i] == true) {
            for(int j = 0; j < m; j++) {
                binrep[j] = false;
            }
            int cnt = 0, tmp = i;
            while(tmp > 0) {
                binrep[cnt] = tmp%2;
                tmp/=2;
                cnt++;
            }
            int rem = 0;
            for(int j = 0; j < m; j++) {
                if(binrep[j] == true) rem += has[j];
            }
            int amn = 0;
            while(amn < n && rem-req[amn] >= 0) {
                rem-=req[amn];
                amn++;
            }
            if(amn == n && rem == 0) {
                printf("YES\n");
                return 0;
            }
            if(amn < n) {
                for(int j = 0; j < m; j++) {
                    if(binrep[j] == false && rem+has[j] <= req[amn]) dp[i+(1<<j)] = true;
                }
            }
        }
    }
    printf("NO\n");
    return 0;
}

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

bank.cpp: In function 'int main()':
bank.cpp:6:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
bank.cpp:8:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |         scanf("%d",&req[i]);
      |         ~~~~~^~~~~~~~~~~~~~
bank.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         scanf("%d",&has[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...