제출 #598423

#제출 시각아이디문제언어결과실행 시간메모리
598423Belgutei은행 (IZhO14_bank)C++17
100 / 100
422 ms8712 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<long long, long long> Point; #define ll long long #define ff first #define ss second #define pb push_back #define mk make_pair #define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define MOD 1000000007 #define MOD1 1000000009 #define sqr(x) sqr((x)*(x)) void debug_out() { cerr << endl; } template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); } #ifdef BE_DEBUG #define debug(...) cerr << "\033[1;31m(" << #__VA_ARGS__ << "):\033[0m", debug_out(__VA_ARGS__) #else #define debug(...) #endif const int N = 1100005; int n,m; int a[30], b[30]; vector<int> v[1005]; bool check[N], tmp[N], ans; int go(int val) { int ret = 0; int cnt = 0; while(val > 0) { if(val % 2 == 1) ret += b[cnt]; val /= 2; cnt ++; } return ret; } int main() { IOS // freopen("bank.in", "r", stdin); // freopen("bank.out", "w", stdout); 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 i = 0; i < (1 << m); i ++) { int val = go(i); if(val <= 1000) { v[val].pb(i); } } check[0] = 1; for(int i = 0; i < n; i ++) { for(int j = 0; j < (1 << m); j ++) { tmp[j] = check[j]; check[j] = 0; } for(int j = 0; j < (1 << m); j ++) { if(tmp[j] == 0) continue; for(auto x: v[a[i]]) { if((x & j) == 0) { check[x | j] = 1; if(i == n - 1) ans = 1; } } } // } if(ans == 1) { cout << "YES"; } else cout << "NO"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...