이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <iomanip>
#include <cmath>
#include <limits>
#include <map>
#include <utility>
#include <cctype>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include<assert.h>
#include <functional>
#include <iterator>
using namespace std;
#define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n";
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define ll long long
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define int long long
int dp[1<<(20)];
int n,m;
vector<int> a,b;
void solve(int i,int mask){
if(i>=n){
cout<<"YES"<<endl;
exit(0);
return;
}
if(dp[mask]!=-1) return;
for(int j=0;j<=(1<<m);j++){
if(j&mask) continue;
int x=0;
for(int k=0;k<m;k++){
if((1<<k)&j) x+=b[k];
}
if(x==a[i]){
solve(i+1,(mask|j));
}
}
dp[mask]=1;
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n>>m;
for(int i=0;i<n;i++) {
int x;
cin>>x;
a.pb(x);
}
for(int i=0;i<m;i++){
int x;
cin>>x;
b.pb(x);
}
memset(dp,-1,sizeof(dp));
solve(0,0);
cout<<"NO"<<endl;
}
# | 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... |