이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
int N, M;
int A[20], B[20];
int dp[21][1<<20];
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> N >> M;
rep(i, N) cin >> A[i];
rep(i, M) cin >> B[i];
rep(i, N+1) rep(j, 1<<M) dp[i][j] = -1;
dp[0][0] = 0;
rep(i, N) {
rep(S, 1<<M) {
if (dp[i][S] == -1) continue;
rep(t, M) if (((S>>t)&1) == 0) dp[i][S|(1<<t)] = dp[i][S]+B[t];
}
rep(S, 1<<M) if (dp[i][S] == A[i]) dp[i+1][S] = 0;
}
bool ok = false;
rep(S, 1<<M) if (dp[N][S] == 0) ok = true;
if (ok) cout << "YES\n";
else cout << "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... |