제출 #1067892

#제출 시각아이디문제언어결과실행 시간메모리
1067892armashka은행 (IZhO14_bank)C++17
100 / 100
489 ms46428 KiB
#include<bits/stdc++.h> // #pragma GCC target("avx2") // #pragma GCC optimize("Ofast") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define file(s) freopen(s".in", "r", stdin);freopen(s".out", "w", stdout); #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define pb push_back #define pf push_front #define ppb pop_back #define ft first #define sd second #define ll long long #define ull unsigned ll #define pii pair<int,int> #define pll pair<ll,ll> const int N = 1e6 + 10; const int M = 1e6 + 5; const int B = 316; const ll msize = 2; const ll mod1 = 1e9 + 7; const ll mod2 = 998244353; const long double Phi = acos(-1); const long long inf = 2e18; const vector <pair<int, int>> dir = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; ll binmul(ll x, ll ti, ll m); ll binpow(ll x, ll ti, ll m); int n, m, a[20], b[20]; unordered_map<int, bool> dp[21]; vector <int> g[1005]; void rec(int id, int mask) { if (id == n) { cout << "YES"; exit(0); } if (dp[id].find(mask) != dp[id].end()) return; for (auto x : g[a[id]]) { int intersection = (x & mask); if (!intersection) { rec(id + 1, x + mask); } } dp[id][mask] = 0; return; } const void solve() { cin >> n >> m; for (int i = 0; i < n; ++ i) cin >> a[i]; for (int i = 0; i < m; ++ i) cin >> b[i]; for (int mask = 0; mask < (1 << m); ++ mask) { int sum = 0; int x = mask, pos = 0; while (x) { if (x & 1) sum += b[pos]; x >>= 1; ++ pos; } if (sum <= 1000) g[sum].pb(mask); } rec(0, 0); cout << "NO\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); srand(time(NULL)); // file("maze"); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int tt = 1; // cin >> tt; for (int i = 1; i <= tt; ++ i) { // cout << "Case " << i << ":\n"; solve(); } #ifndef ONLINE_JUDGE cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; } // Template functions ll binmul(ll x, ll ti, ll m) { ll res = 0;while (ti){if(ti & 1)res += x;x += x;ti >>= 1; x %= m; res %= m;} return res;} ll binpow(ll x, ll ti, ll m) { ll res = 1;while (ti){if(ti & 1)(res *= x)%=m;(x*=x)%=m;ti >>= 1; x %= m; res %= m;} return res;}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...