Submission #922881

#TimeUsernameProblemLanguageResultExecution timeMemory
922881NurislamBank (IZhO14_bank)C++14
27 / 100
4 ms856 KiB
#include <bits/stdc++.h>
#include <iostream>
//~ #include <ext/pb_ds/assoc_container.hpp> 
//~ #include <ext/pb_ds/tree_policy.hpp> 
 
 
using namespace std;
//~ using namespace __gnu_pbds; 
  
 
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
//~ #define double long double 
//~ #define order_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
///*                                                    __                    __                        __                    */
///*        ======     _      /| /|  __   _            /   |  |   /|  |   @  |    |  |  | /   /| |\  | /   |  |  @ | /        */
///* \-       ||  |_| |_     / |/ | |  | |_  |-        |   |--|  /-|  |   |  \ \  |==|  |-   /=| | \ | |   |--|  | |-         */
///*          ||  | | |_    /     | |__|  _| |_        \__ |  | /  |  |__ |  __|  |  |  | \ /  | |  \| \__ |  |  | | \        */
///* 
 
typedef vector<int> vi;
typedef vector<double> vd;
//~ typedef pair<int,int> pii;
//~ typedef vector<pii> vii;
//~ typedef vector<vi> vv;
const int N = 2e5+2, inf = 1e8, mod = 1e9+7;
bool ok = 0;
vi var[22];
int n, m;
map<pair<vi, int>, bool> was;
void rec(vi us, int i){
	if(ok || was[{us, i}])return;
	if(i == n){ok = 1;return;}
	was[{us, i}] = 1;
	for(auto ms:var[i]){
		if(ok)return;
		vi res = us;
		bool ri = 1;
		for(int j = 0; j < m; j++){
			if((ms >> j) & 1){
				if(res[j]){
					ri = 0;
					break;
				}
				res[j] = 1;
			}
		}
		if(ri)rec(res, i+1);
	}
	
}
bool cp(int a, int b){
	if(__builtin_popcount(a) < __builtin_popcount(b))return a < b;
	return a > b;
}
void solve(){
	cin >> n >> m;
	int a[n], b[m];
	map<int,vi> mp;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		mp[a[i]].pb(i);
	}
	for(int &i:b)cin >> i;
	for(int ms = 0; ms < (1<<m); ms++){
		int sum = 0;
		for(int i = 0; i < m; ++i){
			if((ms >> i)&1)sum+=b[i];
		}
		for(auto i:mp[sum])var[i].pb(ms);
	}
	for(int i = 0; i < n; i++)if(var[i].empty()){cout << "NO\n";return;}
	for(auto i:var)sort(all(i), cp);
	vi us(m, 0);
	rec(us, 0);
	if(ok)cout << "YES\n";
	else cout << "NO\n";
}
main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int test = 1;
	//~ cin >> test;
	while(test--){
		solve();
	}
}
 
 
 
 
 
 
 
 
 
 

Compilation message (stderr)

bank.cpp:84:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   84 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...