Submission #170837

#TimeUsernameProblemLanguageResultExecution timeMemory
170837beksultan04은행 (IZhO14_bank)C++14
19 / 100
79 ms4472 KiB
#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define OK puts("OK");
#define sz(s) (int)s.size()
#define pii pair<int,int>
#define all(s) s.begin(), s.end()
#define allr(s) s.rbegin(), s.rend()
#define rep(i,n) for (i=0;i<(n);++i)
#define rep1(i,n) for (i=1;i<=(n);++i)
#define ret return
#define nemeshay ios::sync_with_stdio(0),cin.tie(0);
const int N=30,INF=1e9+7;
int a[N],b[N],n,m,flag=0,mp[(1<<21)];

int sum(int a){
    int i,c=0;
    for (i=0;i<=m;++i)
        if ((a&(1<<i)))
            c+=b[i];
    ret c;
}

void rec(int s,int j){
    if (j==n){
        cout <<"YES";
        exit(0);
    }
    int i;
    for (i=1;i<(1<<m);++i)
        if (s&(!i))
            if (mp[i]==b[j])
                rec((s|i),j+1);




}

main(){
    nemeshay
    int i,c=1;
    cin>>n>>m;
    rep(i,n)cin>>a[i];
    rep(i,m)cin>>b[i];
    for (i=1;i<(1<<m);++i)mp[i]=sum(i);

    for (i=1;i<(1<<m);++i)
        if (mp[i]==a[0])
            rec(i,1);





    if (flag)cout <<"YES";
    else cout <<"NO";
}

Compilation message (stderr)

bank.cpp:43:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
bank.cpp: In function 'int main()':
bank.cpp:45:11: warning: unused variable 'c' [-Wunused-variable]
     int i,c=1;
           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...