Submission #887021

#TimeUsernameProblemLanguageResultExecution timeMemory
887021a_l_i_r_e_z_aBank (IZhO14_bank)C++17
71 / 100
1059 ms10588 KiB
// In the name of Allah // Khodaya khodet komak kon // Hope is last to die // Let's go // Hello today I decided to solve at least 4 great problems per day // 2023/11/24 #pragma GCC optimize("Ofast") #pragma GCC optimize("fast-math") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define pb push_back #define S second #define F first #define mp make_pair #define smax(x, y) (x) = max((x), (y)) #define smin(x, y) (x) = min((x), (y)) #define all(x) (x).begin(), (x).end() #define set_dec(x) cout << fixed << setprecision(x); #define sz(x) ((int)(x).size()) #define file_io freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); const int maxn = 20 + 5, maxB = (1ll << 20); const int inf = 1e9 + 7; int a[maxn], b[maxn], sm[maxB]; bool dp[maxn][maxB]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; 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 = 1; mask < (1ll << m); mask++){ int bit = 31 - __builtin_clz(mask); sm[mask] = sm[mask ^ (1ll << bit)] + b[bit]; } dp[0][0] = 1; for(int i = 0; i < n; i++){ for(int mask = 0; mask < (1ll << m); mask++){ if(!dp[i][mask]) continue; for(int nas = 0; nas < (1ll << m); nas++){ if(nas & mask) continue; if(sm[nas] == a[i]) dp[i + 1][nas | mask] = 1; } } } for(int mask = 0; mask < (1ll << m); mask++){ if(dp[n][mask]){ cout << "YES\n"; return 0; } } cout << "NO\n"; 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...