Submission #1322753

#TimeUsernameProblemLanguageResultExecution timeMemory
1322753dxfBank (IZhO14_bank)C++17
100 / 100
249 ms98916 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; #define change_io() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define el endl #define all(x) begin(x), end(x) #define pb push_back #define mp make_pair #define INF 1000000005 #define LLINF 1e18 #define MOD 1000000007 #define MOD9 998244353 // remove single val from multiset with -> os.find_by_order(os.order_of_key(x)) typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; typedef tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_pair_set; const ll N5 = 1e5 + 5; const ll N6 = 1e6 + 5; const ll NN5=2e5+5; const ll N3=1e3+5; #define dtrap cout << "catch" << el; /*goofball behavior * initialize dps correctly: 0, -INF, INF * change lb and ub for binary search back after making bounds smaller for debugging * check mod in problem statement * don't be an idiot and forget to mod when PS says "return ans mod X" * 1<<i if i > 31 will NOT work because overflow */ set<array<int, 2>> dp[1<<20]; void solve() { int n, m; cin >> n >> m; int ppl[n+1]; ppl[n] = INF; int bn[m]; for (int i = 0; i < n; ++i) { cin >> ppl[i]; } for (int i = 0; i < m; ++i) { cin >> bn[i]; } dp[0].insert({0,0}); bool res = false; for (int i = 0; i < 1<<m; ++i) { for (auto P : dp[i]) { if (P[1]==n) { res=true; goto skip_rest; } for (int j = 0; j < m; ++j) { if (((1<<j)&i)!=0) continue; if (bn[j]+P[0] < ppl[P[1]]) dp[i+(1<<j)].insert({bn[j]+P[0], P[1]}); if (bn[j]+P[0]==ppl[P[1]]) dp[i+(1<<j)].insert({0, P[1]+1}); } } } skip_rest: cout << (res ? "YES" : "NO") << endl; } int main() { //freopen("problemname.in", "r", stdin); //freopen("problemname.out", "w", stdout); change_io(); ll T; T=1; //cin>>T; while (T--) { solve(); } return 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...