Submission #1089369

#TimeUsernameProblemLanguageResultExecution timeMemory
1089369vjudge1은행 (IZhO14_bank)C++17
19 / 100
91 ms47452 KiB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll int
#define F first
#define S second
#define ull unsigned long long
#define db double
#define ldb long double
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define all(x) x.begin(), x.end()

const int mod = 1e9 + 7;
const int N = 2000001;

using namespace std;
using namespace __gnu_pbds;

ll n, m, k, p[N], f[N], a, b, dp[N], ans[N], cnt[N], used[21][N];
vector <ll> g[N];

void rec (ll pos, ll mask){
	if (pos == n + 1){
		cout << "YES";
		exit(0);
	}
	if (used[pos][mask]){
		return;
	}
	used[pos][mask] = 1;
//	cout << pos << ' ' << mask << '\n';
	for (auto i: g[pos]){
		a = i;
		b = 1;
		for (int y = 0; y < m; y++){
			if ((a >> y) & 1){
				if ((mask >> y) & 1){
					b = 0;
					break;
				}
			}
		}
		if (b){
			rec (pos + 1, (mask | b));
		}
	}
}

signed main (){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++){
		cin >> p[i];
	}
	for (int i = 1; i <= m; i++){
		cin >> f[i];
	}
	for (int i = 1; i <= n; i++){
		for (int y = 1; y < (1 << m); y++){
			a = 0;
			for (int j = 0; j < m; j++){
				if ((y >> j) & 1){
					a += f[j + 1];
				}
			}
			if (a == p[i]){
				g[i].pb(y);
			}
		}
	}
	for (int i = 0; i < g[1].size(); i++){
		rec (2, g[1][i]);
	}
	cout << "NO";	
}

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:79:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |  for (int i = 0; i < g[1].size(); i++){
      |                  ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...