# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1247654 | vestonveston | Bank (IZhO14_bank) | C++20 | 538 ms | 17224 KiB |
#include <bits/stdc++.h>
#define name "vestonluvto"
const char* namein = name ".inp";
const char* nameout = name ".out";
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mod ((1ll) << 31) - 1;
#define mod1 ((1ll) << 61) - 1;
#define PI 3.141592653589793238462
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define mask(k) (1 << k)
using namespace std;
#ifndef LOCAL
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
void _print(int t) {cerr << t;}
void _print(long long t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(long double t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(unsigned long long t) {cerr << t;}
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
void homefix(){
#ifndef LOCAL
freopen("fixcode.txt", "w", stderr);
#endif
}
void home(){
homefix();
if (fopen(namein, "r")) {
freopen(namein, "r", stdin);
freopen(nameout, "w", stdout);
}
}
int n, m;
int a[25], b[25];
void nhap(){
cin >> n >> m;
for(int i = 1; i <= n; i++)cin >> a[i];
for(int i = 1; i <= m; i++)cin >> b[i];
}
int dp[1 << 22];
vector<int> luu[50005];
int mu[1 << 22];
void bfsolve(){
for(int i = 0 ; i < m; i++)mu[mask(i)] = i;
for(int i = 1; i < mask(m); i++){
int nn = i & (-i);
int j = mu[nn] + 1;
dp[i] = dp[(i^nn)] + b[j];
luu[dp[i]].push_back(i);
}
}
int f[1 << 22];
void solve(){bfsolve();
for(int mas = 0; mas < mask(m); mas++){
int j = f[mas] + 1;
if(j == n+1){
cout << "YES";
return;
}
for(int &p : luu[a[j]]){
if((mas | p) == mas + p){
f[mas+p] = max(f[mas+p], j);
if(j == n){
cout << "YES";
return;
}
}
}
}
cout << "NO";
}
int main(){
fastio(); home();int t = 1;
//cin >> t;
while(t--)nhap(), solve();
return 0;
}
/* ___________
╔══╗ ▐▀▄ ▄▀▌ ▄▄▄▄▄▄▄ / \
╚╗╔╝ ▌▒▒▀▄▄▄▄▄▀▒▒▐▄▀▀▒██▒██▒▀▀ / MEO \
╔╝(¯’v´¯) ▐▒▒▒▒▀▒▀▒▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀▄ \
╚══’.¸. ▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄▒▒▒▒▒▒▒▒▒▒▒▒▀▄ \ __________ /
╔♫═╗╔╗ kitten ▀█▒▒▒█▌▒▒█▒▒▐█▒▒▒▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌ |/
╚╗╔╝║║♫═╦╦╦╔╗ ▀▌▒▒▒▒▒▒▀▒▀▒▒▒▒▒▒▀▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐ ▄▄
╔╝╚╗♫╚╣║║║║╔╣ ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌▄█▒█
╚═♫╝╚═╩═╩♫╩═╝ ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒█▀
┊ ┊ ┊ ┊ ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▀
┊ ┊ ┊ ┊ ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌
┊ ┊ ┊ ★ ▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐
┊ ┊ ☆ ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌
┊ ★ ▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐
☆ ▐▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄▌
▀▄▄▀▀▀▀▀▄▄▀▀▀▀▀▀▀▄▄▀▀▀▀▀▄▄▀
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |