제출 #1094928

#제출 시각아이디문제언어결과실행 시간메모리
1094928rayan_bdBank (IZhO14_bank)C++17
0 / 100
1 ms604 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; 


#define getar(ar,n) for(ll i=0;i<n;++i) cin>>ar[i]
#define show(n) cout<<n<<'\n'
#define all(v) v.begin(), v.end()
#define br cout<<"\n"
#define pb push_back
#define nl '\n'
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define ret return
#define ll long long
#define ld long double
#define sza(x) ((int)x.size())

const int mxN = 2048;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ld EPS = 1e-9;

ll need[30],curr[30];
vector<ll> money[mxN];


bool f(ll i,ll mask){
	if(i<0) return 1;
	if(money[need[i]].size()==0) return 0;
	bool ok=0;
	for(auto it:money[need[i]]){
		for(ll j=0;j<31;++j){
			if(!mask&(1<<j)&&it&(1ll<<j)){
				ok|=f(i-1,mask|it);
			}
		}
	}
	return ok;
}

void solve(ll tc) {
  ll n,m;cin>>n>>m;
  for(ll i=0;i<n;++i) cin>>need[i];
  for(ll i=0;i<m;++i) cin>>curr[i];
  
  for(ll mask=0;mask<=(1ll<<m);++mask){
  	ll tot=0;
  	for(ll i=0;i<m;++i){
  		if(mask&(1ll<<i)) tot+=curr[i];
  	}
  	money[tot].pb(mask);
  }
  if(f(n-1,0)) yes;
  else no;
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    solve(0);
    return 0;
}

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

bank.cpp: In function 'bool f(long long int, long long int)':
bank.cpp:38:7: warning: suggest parentheses around operand of '!' or change '&' to '&&' or '!' to '~' [-Wparentheses]
   38 |    if(!mask&(1<<j)&&it&(1ll<<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...