이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define ll long long
#define pb push_back
#define eb emplace_back
#define pu push
#define ins insert
#define bruh ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ff(x,a,b,c) for (auto x=a;x<=b;x+=c)
#define fd(x,a,b,c) for (auto x=a;x>=b;x-=c)
#define int ll
using namespace std;
const int N = 1e6+5;
const int mod = 1e9+7;
int power(int a,int b) {ll x = 1;if (a >= mod) a%=mod; while (b) {if (b & 1) x = x*a % mod;a = a*a % mod;b>>=1;}return x;}
void solve()
{
int n,m;
cin>>n>>m;
vector<int> a(n),b(m);
for (int i=0;i<n;i++) cin>>a[i];
for (int j=0;j<m;j++) cin>>b[j];
vector<pair<int,int>> dp((1<<m),{0,0});
bool check[1<<m] {false}; check[0] = true;
for (int mask=0;mask<(1<<m);mask++)
{
for (int i=0;i<m;i++)
{
if (mask & (1<<i) && check[mask ^ (1<<i)])
{
int nmask = mask ^ (1<<i);
int cur = dp[nmask].second+b[i];
if (cur==a[dp[nmask].first]) dp[mask] = {dp[nmask].first+1,0}, check[mask] = true;
else if (cur<a[dp[nmask].first]) dp[mask] = {dp[nmask].first,cur},check[mask] = true;
}
}
if (dp[mask].first==n)
{
cout<<"YES"; return;
}
}
cout<<"NO";
}
signed main()
{
bruh
int t = 1;
//cin>>t;
while (t--)
{
solve();
//cout<<"\n";
}
}
# | 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... |