Submission #651327

#TimeUsernameProblemLanguageResultExecution timeMemory
651327mychecksedadBank (IZhO14_bank)C++17
100 / 100
102 ms6860 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long int ll; typedef long double ld; #define MOD (1000000000+7) #define MOD1 (998244353) #define PI 3.1415926535 #define pb push_back #define setp() cout << setprecision(15) #define all(x) x.begin(), x.end() #define debug(x) cerr << #x << " is " << x << '\n'; const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 23; int n, m, a[N], b[N]; vector<int> v[1005], bank, used(K), sums[1005], people, dp[K]; bitset<(1<<20)> dpp[K]; void solve(){ cin >> n >> m; for(int i = 1; i <= n; ++i) cin >> a[i]; for(int i = 1; i <= m; ++i) cin >> b[i]; if(n>m){ cout << "NO"; return; } cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n"; for(int i = 1; i <= n; ++i) v[a[i]].pb(i); for(int i = 1; i <= m; ++i){ if(!v[b[i]].empty()){ used[v[b[i]].back()] = 1; v[b[i]].pop_back(); }else{ bank.pb(b[i]); } } for(int i = 1; i <= n; ++i) if(!used[i]) people.pb(a[i]); m = bank.size(); n = people.size(); if(m < 2*n){ cout << "NO"; return; } if(!n){ cout << "YES"; return; } for(int mask = 0; mask < (1<<m); ++mask){ int sum = 0; for(int j = 0; j < m; ++j) if((1<<j)&mask) sum += bank[j]; if(sum <= 1000) sums[sum].pb(mask); } dp[0] = sums[people[0]]; for(int j = 1; j < n; ++j){ bool ok = 0; for(int submask: dp[j - 1]){ for(int subbank: sums[people[j]]){ if(!(submask & subbank)){ ok = 1; if(!dpp[j][subbank|submask]){ dpp[j][subbank|submask] = 1; dp[j].pb(subbank|submask); } } } } } if(!dp[n - 1].empty()){ cout << "YES"; }else{ cout << "NO"; } } int main(){ cin.tie(0); ios::sync_with_stdio(0); int T = 1, aa; // cin >> T;aa=T; while(T--){ // cout << "Case #" << aa-T << ": "; solve(); cout << '\n'; } cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n"; return 0; }

Compilation message (stderr)

bank.cpp: In function 'void solve()':
bank.cpp:61:14: warning: variable 'ok' set but not used [-Wunused-but-set-variable]
   61 |         bool ok = 0;
      |              ^~
bank.cpp: In function 'int main()':
bank.cpp:87:16: warning: unused variable 'aa' [-Wunused-variable]
   87 |     int T = 1, aa;
      |                ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...