Submission #1085811

#TimeUsernameProblemLanguageResultExecution timeMemory
1085811ThylOneBank (IZhO14_bank)C++14
100 / 100
103 ms4560 KiB
//#################### //Bank //#################### #include<bits/stdc++.h> using namespace std; int n,m; int a[20]; int b[20]; int sum[20]; int dp[(1<<20)+1]; int solve(int bitmask){ if(dp[bitmask]!=-1)return dp[bitmask]; int pos = 0; int s = 0; for(int i = 0;i<m;i++)if((bitmask>>i)&1)s+=b[i]; int bonus = 0; for(int i = 0;i<n;i++) if(sum[i]==s) bonus = 1; int re = bonus; for(int i = 0;i<m;i++){ if(!((bitmask>>i)&1)){ re =max(re,bonus+ solve(bitmask ^ (1<<i))); } } return dp[bitmask]=re; } signed main(){ for(int i = 0;i<(1<<20)+1;i++)dp[i] = -1; ios::sync_with_stdio(false); cin.tie(0); cin>>n>>m; for(int i= 0;i<n;i++)cin>>a[i]; for(int i = 0;i<m;i++)cin>>b[i]; sum[0] = a[0]; for(int i = 1;i<n;i++)sum[i] = a[i] + sum[i-1]; int re = solve(0); if(solve(0)==n) cout << "YES" << endl; else cout << "NO" << endl;; return 0; };

Compilation message (stderr)

bank.cpp: In function 'int solve(int)':
bank.cpp:14:9: warning: unused variable 'pos' [-Wunused-variable]
   14 |     int pos = 0;
      |         ^~~
bank.cpp: In function 'int main()':
bank.cpp:38:9: warning: unused variable 're' [-Wunused-variable]
   38 |     int re = solve(0);
      |         ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...