이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ll long long
struct P{
ll x, y;
};
void dbg_out() { cerr << endl; }
template <typename H, typename... T>
void dbg_out(H h, T... t) { cerr << ' ' << h; dbg_out(t...); }
#define dbg(...) { cerr << #__VA_ARGS__ << ':'; dbg_out(__VA_ARGS__); }
const int MAXN = 1<<20;
int dp[MAXN], r[MAXN];
signed main(){
fastio;
memset(dp, -1, sizeof(dp));
int n, m;
cin >> n >> m;
vector<int> pay (n), notes (m);
for (auto &a: pay) cin >> a;
for (auto &a: notes) cin >> a;
bool ans=false;
for (int mask=1; mask<(1<<m); mask++){
for (int i=0; i<m; i++){
if (mask & (1 << i)) continue;
int nxt = mask ^ (1 << i);
int goal = dp[mask]+1;
if (dp[nxt] >= goal) continue;
if (r[mask] + notes[i] == pay[goal]){
dp[nxt] = goal;
r[nxt] = 0;
}
else{
dp[nxt] = dp[mask];
r[nxt] = r[mask] + notes[i];
}
if (dp[nxt] == n-1) {
ans = true;
break;
}
}
}
cout << (ans? "YES" : "NO") << '\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... |