제출 #1355319

#제출 시각아이디문제언어결과실행 시간메모리
1355319kmath628은행 (IZhO14_bank)C++20
100 / 100
86 ms8584 KiB
#include <bits/stdc++.h>
using namespace std;
pair<int,int> dp[1<<20];
int a[20],b[20];
int main(){
    int n,m,i,j,k,ans=0;
    scanf("%d %d",&n,&m);
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    for(i=0;i<m;i++) scanf("%d",&b[i]);
    for(i=1;i<(1<<m);i++){
        dp[i]={-1,-1};
        for(j=0;j<m;j++){
            if(!(i&(1<<j))) continue;
            k=i^(1<<j);
            if(dp[k].first!=-1 && dp[k].second+b[j]<=a[dp[k].first]){
                dp[i]=dp[k];
                dp[i].second+=b[j];
                if(dp[i].second==a[dp[i].first]){
                    dp[i].second=0;
                    dp[i].first++;
                }
                if(dp[i].first==n){
                    dp[i].first=-1;
                    ans=1;
                }
            }
        }
    }
    if(ans) printf("YES\n");
    else printf("NO\n");
    return 0;
}

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

bank.cpp: In function 'int main()':
bank.cpp:7:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
bank.cpp:8:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     for(i=0;i<n;i++) scanf("%d",&a[i]);
      |                      ~~~~~^~~~~~~~~~~~
bank.cpp:9:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     for(i=0;i<m;i++) scanf("%d",&b[i]);
      |                      ~~~~~^~~~~~~~~~~~
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…