제출 #961088

#제출 시각아이디문제언어결과실행 시간메모리
961088Kavelmydex은행 (IZhO14_bank)C++17
71 / 100
534 ms135860 KiB
#include <bits/stdc++.h> using namespace std; // #define int long long #define pi pair<int,int> #define vi vector<int> #define rep(i,x,n) for(int i=x; i<n; ++i) #define For(i,n) rep(i,0,n) #define endl "\n" #define sp ' ' #define pb push_back #define f first #define s second #define sz size() #define all(x) (x).begin(),(x).end() const int N = 20, OO = 2e9, mod = 1e9+7, mx = 1e3+1; const int dx[]{0,1}, dy[]{1,0}; void tr(int a, int b){cout << a << sp << b << endl;} void cmx(int &a, int b){a = max(a,b);} void cmn(int &a, int b){a = min(a,b);} int dp[1<<N], a[N], b[N]; bitset <mx> bt[1<<N]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); // freopen("talent.in", "r", stdin); // freopen("talent.out", "w", stdout); int n,m; cin >> n >> m; For(i,n) cin >> a[i]; For(i,m) cin >> b[i]; For(i,m){ bt[1<<i][0] = 1; bt[1<<i] |= (bt[1<<i] << b[i]); if(bt[1<<i][a[0]]){ dp[1<<i]++; } } for(int msk=3; msk < 1<<m; ++msk){ if(__builtin_popcount(msk)==1) continue; For(i,m) if((1<<i)&msk){ int other = msk - (1<<i); bitset<mx> cur = bt[other]; cur |= (cur<<b[i]); if(dp[other] < n && cur[a[dp[other]]]){ if(dp[msk] < dp[other]+1){ dp[msk] = dp[other]+1; bt[msk].reset(); bt[msk][0] = 1; } }else{ if(dp[msk] < dp[other]){ dp[msk] = dp[other]; bt[msk] = cur; } else if(dp[msk]==dp[other]){ bt[msk] |= cur; } } } } if(dp[(1<<m)-1] == n) cout << "YES"; else cout << "NO"; cout << endl; return 0; } /* Just some notices : I believe you can do it ! You've done things that were harder ... Stay calm and focused =) */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...