이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define pb push_back
#define endl '\n'
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define setmin(x,y) x=min((x),(y))
#define setmax(x,y) x=max((x),(y))
#define fi first
#define se second
// mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count());
// int rand(int l,int r){return l+((hdp()%(r-l+1))+r-l+1)%(r-l+1);}
const int N = 20;
const int D = 1e3+5;
const int mod = 998244353;
const int SQ = 450;
// const int inf = 1e18;
int n,k,a[20],b[20];
pair<int,int> dp[1<<N];
signed main()
{
fastIO
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
cin>>k>>n;
for(int i=0;i<k;i++) cin>>a[i];
for(int i=0;i<n;i++) cin>>b[i];
for(int m=1;m<(1<<n);m++)
{
for(int sm=m;sm>0;)
{
int l=(sm&-sm); int p=m^l;
if(dp[p].fi<n&&dp[p].se+b[__lg(l)]==a[dp[p].fi]) setmax(dp[m],make_pair(dp[p].fi+1,0));
else setmax(dp[m],make_pair(dp[p].fi,dp[p].se+b[__lg(l)]));
sm^=l;
}
}
cout<<(dp[(1<<n)-1].fi==k?"YES":"NO");
}
# | 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... |