답안 #68548

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68548 2018-08-17T09:41:57 Z quoriess 은행 (IZhO14_bank) C++14
19 / 100
73 ms 1940 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main(){
	int n,m;
	cin>>n>>m;
	vector<int> salary,banks;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin>>a;
		salary.push_back(a);
	}
	for (int j = 0; j < m; j++)
	{
		int a;
		cin>>a;
		banks.push_back(a);
	}
	vector<bitset<20> > sncler[n];
	for (int i = 0; i < 1<<m; i++)
	{
		bitset<20> smd(i);
		int tplm=0;
		for (int j = 0; j < m; j++)
		{
			if(smd[j])tplm+=banks[j];
		}
		for(int j=0;j<n;j++){
			if(salary[j]==tplm)
                sncler[j].push_back(smd);
		}
	}
	int mstb=1<<m;
	bool dp[n][mstb];
	set<int> bakilacaklar;
	for(int i=0;i<n;i++){
        for(int j=0;j<mstb;j++)dp[i][j]=0;
	}
	for(auto j:sncler[0])
	{
		dp[0][j.to_ulong()]=1;
		bakilacaklar.insert(j.to_ulong());
	}
	for (int i = 1; i < n; i++)
	{
		//her aşamada mstb'yi azaltarak git
		//eğer dp[i-1][a] false ise bakmaya gerek yok
		set<int> nb=bakilacaklar;
		for(auto k:bakilacaklar){
			for (auto j: sncler[i])
			{
				if(k&&j.to_ulong()==0){
					dp[i][k^j.to_ulong()]=dp[i-1][k]||dp[i][k^j.to_ulong()];
					if(dp[i][k^j.to_ulong()])nb.insert(k^j.to_ulong());
				}
			}
		}
		bakilacaklar=nb;
	}
	bool ans=0;
    for(int i=1;i<mstb;i++)if(dp[n-1][i])ans=true;
    cout << (ans?"YES":"NO")<<"\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 4 ms 464 KB Output is correct
5 Correct 72 ms 1548 KB Output is correct
6 Correct 2 ms 1548 KB Output is correct
7 Correct 2 ms 1548 KB Output is correct
8 Correct 73 ms 1940 KB Output is correct
9 Correct 73 ms 1940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 4 ms 464 KB Output is correct
5 Correct 72 ms 1548 KB Output is correct
6 Correct 2 ms 1548 KB Output is correct
7 Correct 2 ms 1548 KB Output is correct
8 Correct 73 ms 1940 KB Output is correct
9 Correct 73 ms 1940 KB Output is correct
10 Incorrect 2 ms 1940 KB Output isn't correct
11 Halted 0 ms 0 KB -