이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
long long n,m,ch[22],cash[22];
bool ans=false;
vector<long long> hi;
vector<long long> num[40004];
void create(long long bitsm,long long vr,long long ob){
//cout<<vr<<"ob"<<bitsm<<endl;
if(vr==m){
num[ob].push_back(bitsm);
return;
}
create(bitsm,vr+1,ob);
bitsm = bitsm + (1 << vr);
create(bitsm,vr+1,ob+cash[vr]);
}
void solve(long long bitsm,long long vr){
if(vr==n)ans=true;
if(ans==true)return ;
for(int j=0;j<num[ch[vr]].size() && ans==false;j++){
bool krai=false;
int s1=bitsm,s2=num[ch[vr]][j];
while(s1>0 || s2>0){
if(s1%2==1 && s2%2==1){
krai=true;
}
s1/=2;
s2/=2;
}
if(krai==false){
int nov = bitsm + num[ch[vr]][j];
//cout<<bitsm<<" "<<num[ch[vr]][j]<<"ddd"<<endl;
solve(nov, vr+1);
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m;
for(int i=0;i<n;i++)cin>>ch[i];
for(int i=0;i<m;i++)cin>>cash[i];
create(0,0,0);
solve(0,0);
if(ans==false)cout<<"NO"<<endl;
else cout<<"YES"<<endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'void solve(long long int, long long int)':
bank.cpp:24:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(int j=0;j<num[ch[vr]].size() && ans==false;j++){
| ~^~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |