제출 #1033448

#제출 시각아이디문제언어결과실행 시간메모리
1033448bytecode_1234은행 (IZhO14_bank)C++17
19 / 100
131 ms8540 KiB
#include<bits/stdc++.h>
using namespace std;
using ll=int;


int main()
{
	// #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif

     ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    
    	ll n,m;
    	cin>>n>>m;
    	vector<ll> v(n);
    	for(ll i=0;i<n;i++)
    	{
    		cin>>v[i];
    	}
    	vector<ll> v1(m);
    	for(ll i=0;i<m;i++)
    	{
    		cin>>v1[i];
    	}

    	
    	vector<vector<ll>> dp1(n,vector<ll>(pow(2,m),-1));
    	vector<vector<ll>> dp2(n);
        ll f=0;
    	for(ll i=0;i<n;i++)
    	{
    		for(ll j=0;j<=pow(2,m);j++)
    		{
    			ll sum=0;
    			for(ll k=0;k<m;k++)
    			{
    				if(j&(1<<k))
    				{
    					sum+=v1[k];
    				}
    			}

    			if(sum==v[i])
    			{
    				dp2[i].push_back(j);
    			}
    		}

    		if(dp2[i].size()==0)
    		{
              f=1;
              break;
    		}

    		
    	}

    	
    	for(ll i=0;i<n;i++)
    	{
    		for(ll j=0;j<=pow(2,m);j++)
    		{
    			ll sum=0;
    			for(ll k=0;k<m;k++)
    			{
    				if(j&(1<<k))
    				{
    					sum+=v1[k];
    				}
    			}

    			if(sum==v[i])
    			{
    				dp1[i][j]=0;
    			}
    		}

    		
    	}


    	if(f)
    	{

    		cout<<"NO"<<"\n";
    	}
    	else if(n==1)
    	{
    		if(dp2[0].size()>0)
    		{
    			cout<<"YES"<<"\n";
    		}
    		else
    		{
    			cout<<"NO"<<"\n";
    		}
    	}
    	else
    	{
    		vector<vector<ll>> dp(n+1,vector<ll>(pow(2,m),-1));
    		for(ll i=0;i<pow(2,m);i++)
    		{
    			dp[0][i]=0;
    		}

    		for(ll i=1;i<=n;i++)
    		{
    			for(ll j=0;j<dp2[i-1].size();j++)
    			{
    				ll x=pow(2,m)-1;
    				if(x&(dp2[i-1][j])==dp2[i-1][j])
    				{
    					if(dp1[i-1][x^(dp2[i-1][j])]==0)
    					{
    						dp[i][x]=0;
    						break;
    					}
    				}
    			}
    		}

    		if(dp[n][pow(2,m)-1]==0)
    		{
    			cout<<"YES"<<"\n";
    		}
    		else
    		{
    			cout<<"NO"<<"\n";
    		}
    	}
}

컴파일 시 표준 에러 (stderr) 메시지

bank.cpp: In function 'int main()':
bank.cpp:112:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |        for(ll j=0;j<dp2[i-1].size();j++)
      |                   ~^~~~~~~~~~~~~~~~
bank.cpp:115:27: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
  115 |         if(x&(dp2[i-1][j])==dp2[i-1][j])
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...