Submission #935093

#TimeUsernameProblemLanguageResultExecution timeMemory
935093ntdaccodeBank (IZhO14_bank)C++17
71 / 100
1030 ms44260 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,f[1<<20]; bool dd[21][1<<20],d[21][1<<20]; 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,check=0; fori(mask,1,(1<<m)-1) { fori(i,1,m) { if(mask&(1<<(i-1))) f[mask]+=b[i]; } } fori(i,1,n) { check=0; sum+=a[i]; fori(mask,1,(1<<m)-1) { if(f[mask]>sum) continue; 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; break; } } } if(f[mask]==sum&&OK) { dd[i][mask]=true; check=1; } } } if(check) cout << "YES\n"; else cout << "NO\n"; }

Compilation message (stderr)

bank.cpp: In function 'int32_t main()':
bank.cpp:21:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     freopen("1.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
bank.cpp:22:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     freopen("1.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
bank.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     freopen("bank.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bank.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     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...