Submission #935087

#TimeUsernameProblemLanguageResultExecution timeMemory
935087ntdaccodeBank (IZhO14_bank)C++17
71 / 100
1055 ms22100 KiB
#include<bits/stdc++.h> #define fori(i,a,b) for(int i=a;i<=b;i++) #define ll long long #define ii pair<int,int> #define fi first #define se second #define pb push_back using namespace std; const int mod=1e9+7; const int M=1e6+10; const int N=1e3+10; int n,a[21],b[21],m; bool dd[21][1<<20],d[21][1<<20]; bool check() { fori(i,1,(1<<m)-1) { if(dd[n][i]) return true; } return false; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen("1.inp","r")) { freopen("1.inp","r",stdin); freopen("1.out","w",stdout); } if(fopen("bank.inp","r")) { freopen("bank.inp","r",stdin); freopen("bank.out","w",stdout); } cin >> n >> m; fori(i,1,n) cin >> a[i]; fori(i,1,m) cin >> b[i]; dd[0][0]=true; int sum=0; fori(i,1,n) { sum+=a[i]; fori(mask,1,(1<<m)-1) { //cout << mask << "\n"; int res=0; bool OK=0; fori(j,1,m) { if(mask&(1<<(j-1))) { int bit=mask^(1<<(j-1)); if(dd[i-1][bit]||d[i][bit]) { d[i][mask]=true; OK=1; } res+=b[j]; } } //cout << res << " " << sum << " " << OK << "\n"; if(res==sum&&OK) dd[i][mask]=true; } } if(check()) cout << "YES\n"; else cout << "NO\n"; }

Compilation message (stderr)

bank.cpp: In function 'int32_t main()':
bank.cpp:29:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     freopen("1.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
bank.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen("1.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
bank.cpp:34:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     freopen("bank.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bank.cpp:35:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     freopen("bank.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...