Submission #340632

#TimeUsernameProblemLanguageResultExecution timeMemory
340632beksultan04Bank (IZhO14_bank)C++14
100 / 100
572 ms25836 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scanl(a) scanf("%lld",&a);
#define scanll(a,b) scanf("%lld %lld",&a, &b);
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define scan1(a) scanf("%d",&a);
#define scan2(a,b) scanf("%d %d",&a, &b);
#define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
#define eps 1e-12
const int N = 1108576,INF=1e9+7;
int a[30],b[30],n,m;
bool dp[30][N];
bool vis[30][N];
vector <int> v[30];


bool rec(int x,int mask){
    if (x == n)ret 1;
    if (vis[x][mask])ret dp[x][mask];
    vis[x][mask]=1;
    int i;
    for (i=0;i<v[x].size();++i){

        if (!(mask&v[x][i])){
            bool s = rec(x+1,mask^v[x][i]);
            if (s)dp[x][mask]=1;
        }

    }


    ret dp[x][mask];
}

main(){
    int i,j,mask;
    scan2(n,m)
    for (i=0;i<n;++i)
        scan1(a[i])
    for (i=0;i<m;++i)
        scan1(b[i])
    int x = 0;
    for (mask = 0 ;mask < (1<<m);++mask){
        int sum =0;
        for (j=0;j < m;++j){
            if (mask&(1<<j))sum+=b[j];
        }
        for (j=0;j<n;++j){
            if (sum == a[j]){
                v[j].pb(mask);
            }
        }
    }
    bool f = rec(0,0);
    if (f)YES
    else NO

}






Compilation message (stderr)

bank.cpp: In function 'bool rec(int, int)':
bank.cpp:35:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for (i=0;i<v[x].size();++i){
      |              ~^~~~~~~~~~~~
bank.cpp: At global scope:
bank.cpp:48:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   48 | main(){
      |      ^
bank.cpp: In function 'int main()':
bank.cpp:55:9: warning: unused variable 'x' [-Wunused-variable]
   55 |     int x = 0;
      |         ^
bank.cpp:15:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 | #define scan2(a,b) scanf("%d %d",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~
bank.cpp:50:5: note: in expansion of macro 'scan2'
   50 |     scan2(n,m)
      |     ^~~~~
bank.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 | #define scan1(a) scanf("%d",&a);
      |                  ~~~~~^~~~~~~~~
bank.cpp:52:9: note: in expansion of macro 'scan1'
   52 |         scan1(a[i])
      |         ^~~~~
bank.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 | #define scan1(a) scanf("%d",&a);
      |                  ~~~~~^~~~~~~~~
bank.cpp:54:9: note: in expansion of macro 'scan1'
   54 |         scan1(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...