# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
376145 | panda | 은행 (IZhO14_bank) | C++14 | 963 ms | 86784 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <assert.h>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;
const int MX = 20;
const int MOD = 1e9 + 7;
const int INF = 2e9;
#define F0R(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define rsz resize
#define lb lower_bound
#define ub upper_bound
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
ios_base::sync_with_stdio(0); cin.tie(0);
if (sz(s)) { setIn(s+".in"), setOut(s+".out"); }
}
int N, M, A[MX + 5], B[MX + 5];
int dp[MX + 5][(1 << MX)];
int main() {
F0R(i, MX + 1) F0R(j, (1 << MX)) dp[i][j] = -1;
cin >> N >> M;
FOR(i, 1, N + 1) cin >> A[i];
FOR(i, 1, M + 1) cin >> B[i];
dp[0][0] = 0;
for (int i = 1; i <= N; i++) {
for (int j = 0; j < (1 << M); j++) if (dp[i - 1][j] == 0) dp[i][j] = dp[i - 1][j] + A[i];
for (int j = 1; j <= M; j++) {
for (int k = 0; k < (1 << M); k++) {
//cout << "on bitmask: " << k << " for " << i << "\n";
if (dp[i][k] != -1 && !(k & (1 << (j - 1))) && dp[i][k] - B[j] >= 0) {
//cout << "Passed bitmask: " << k << "\n";
dp[i][k | (1 << (j - 1))] = dp[i][k] - B[j];
//cout << i << ", " << (k | (1 << (j - 1))) << " has the value: " << dp[i][k | (1 << (j - 1))] << "\n";
}
}
}
}
bool good = 0;
F0R(i, (1 << MX)) if (dp[N][i] == 0) {
good = 1;
//cout << N << " with bitmask " << i << "\n";
//cout << "We've used the notes: \n";
//for (int k = 1; k <= M; k++) if (i & (1 << (k - 1))) cout << k << " ";
//cout << "\n";
}
cout << (good ? "YES\n" : "NO\n");
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |