이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <cstring>
#include <climits>
#include <functional>
#include<cstdlib>
//#include "arc.h"
//#include "dreaming.h"
using namespace std;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long LL;
const int MAXN = 2e6 + 11;
using ll = long long;
const ll mod1 = 1e9 + 7;
const ll mod2 = 1000000021;
const ll P = 31;
/*
void setIO(string name = "") {
cin.tie(0)->sync_with_stdio(0); // see /general/fast-io
if ((name.size())) {
freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output
freopen((name + ".out").c_str(), "w", stdout);
}
}
*/
int n, m;
int a[MAXN];
int b[MAXN];
pair<int, int> dp[MAXN];
int flag;
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
//setIO("movie");
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < m; i++)
cin >> b[i];
for (int mask = 0; mask < (1 << m); mask++)
{
for (int j = 0; j < m; j++)
{
pair<int, int> cur = dp[mask ^ (1 << j)];
if (((1 << j) & mask) == 0)
continue;
int C = b[j];
if (cur.second + C == a[cur.first])
{
dp[mask] = { cur.first + 1,0 };
}
else if(cur.second + C <= a[cur.first])
{
dp[mask] = max(dp[mask], make_pair(cur.first,cur.second + C));
}
}
// for (int j = 0; j < m; j++)
//if ((1 << j) & mask)
//cout << 1;
//else
// cout << 0;
//cout << " " << dp[mask].first << " " << dp[mask].second << '\n';
if (dp[mask].first == n)
flag = 1;
}
cout << (flag ? "YES\n" : "NO\n");
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... |