이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int i=a;i<b;i++)
#define af(i,a,b) for(int i=a;i>=b;i--)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int maxN=2e5+5;
const ll inf=1e12;
int n,m;
vector<int> v,u;
bool xx=false;
int vis[30];
void prob(int i, int j){
/*f(l,0,n){
cout<<v[l]<<" ";
}
cout<<"\n";
f(l,0,m){
cout<<vis[l]<<" ";
}
cout<<"\n";
*/
if(i==n){
xx=true;
return;
}
if(v[i]==0){
f(x,0,m) prob(i+1,x);
return;
}
if(vis[j]==1) return;
if(v[i]<u[j]) return;
vis[j]=1;
v[i]-=u[j];
f(x,j+1,m){
prob(i,x);
}
v[i]+=u[j];
vis[j]=0;
}
void go(){
cin>>n>>m;
int a;
f(i,0,n){
cin>>a;
v.PB(a);
}
f(i,0,m){
cin>>a;
u.PB(a);
}
u.PB(0);
m++;
f(i,0,m) prob(0,i);
if(xx) cout<<"YES\n";
else cout<<"NO\n";
}
int main(){
fastio;
int test=1;
//cin>>test;
f(i,1,test+1){
//cout<<"Case "<<i<<":\n";
go();
}
return 0;
}
# | 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... |