제출 #704098

#제출 시각아이디문제언어결과실행 시간메모리
704098thrasherr_1은행 (IZhO14_bank)C++17
100 / 100
282 ms16724 KiB
#include <bits/stdc++.h> using namespace std ; #define ff first #define ss second #define pb push_back #define lb lower_bound #define ub upper_bound #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define ones(x) __builtin_popcount(x) #define remove(v) v.erase(unique(all(v)), v.end()) #define rep(i, a, b) for(int i = a; i <= b; i++) #define per(i, a, b) for(int i = a; i >= b; i--) #ifdef local #include "C:\debug.h" #else #define dbg(x...) 42 #endif #define int long long const int N = 2e6 + 2 ; const int MOD = 1e9 + 7 ; const int P = 1007 ; int n , m , a[21] , b[21] , pref[21] ; int dp[(1 << 21)] ; bool go(int i , int mask , int cur) { if(cur == pref[i]) i++ ; if(i > n) return 1 ; if(~dp[mask]) return dp[mask] ; bool current = 0 ; rep(j , 0 , m - 1) { if(!(mask >> j & 1) && cur + b[j + 1] <= pref[i]) { current |= go(i , (mask | (1 << j)) , cur + b[j + 1]) ; } } dp[mask] = current ; return dp[mask] ; } void solve(){ cin >> n >> m ; rep(i , 0 , (1 << 21) - 1) dp[i] = -1 ; rep(i , 1 , n) cin >> a[i] ; rep(i , 1 , m) cin >> b[i] ; rep(i , 1 , n) pref[i] = pref[i - 1] + a[i] ; bool ok = go(1 , 0 , 0) ; if(ok) cout << "YES\n" ; else cout << "NO\n" ; } signed main () { // ios::sync_with_stdio(false) ; // cin.tie(0) ; int test = 1 ; // cin >> test ; for(int i = 1 ; i <= test ; i++) { solve() ; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...