Submission #676209

#TimeUsernameProblemLanguageResultExecution timeMemory
676209murad_2005Bank (IZhO14_bank)C++14
52 / 100
1092 ms12576 KiB
#include<bits/stdc++.h> #define ll long long #define pii pair<int, int> #define piii pair<pii, int> #define pllll pair<ll, ll> #define pb push_back #define all(v) v.begin(), v.end() #define size(v) v.size() #define INF 2e18 #define f first #define s second using namespace std; void solve(){ int n, m; cin >> n >> m; vector<int>a(n + 1), b(m + 1); for(int i = 1; i <= n; ++i){ scanf("%d", &a[i]); }for(int i = 1; i <= m; ++i){ scanf("%d", &b[i]); } vector<int>List[n + 1]; for(int mask = 1; mask < (1 << m); ++mask){ ll Total = 0; for(int i = 0; i < m; ++i){ if(mask & (1 << i)){ Total += b[i + 1]; } } for(int i = 0; i < n; ++i){ if(Total == a[i + 1]){ List[i + 1].pb(mask); } } } vector<vector<int>>dp(n + 1, vector<int>(1 << m, 0)); for(int i = 1; i <= n; ++i){ for(int mask = 0; mask < (1 << m); ++mask){ dp[0][mask] = 1; for(int j = 0; j < size(List[i]); ++j){ if((mask & List[i][j]) == List[i][j]){ dp[i][mask] = max(dp[i][mask], dp[i - 1][mask ^ List[i][j]]); } } } } if(dp[n][(1 << m) - 1] == 1){ printf("%s\n", "YES"); }else{ printf("%s\n", "NO"); } } int main(){ int t; t = 1; //cin >> t; while(t--){ solve(); } return 0; }

Compilation message (stderr)

bank.cpp: In function 'void solve()':
bank.cpp:42:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |             for(int j = 0; j < size(List[i]); ++j){
      |                              ^
bank.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
bank.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         scanf("%d", &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...