# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
332222 | topovik | Bank (IZhO14_bank) | C++14 | 158 ms | 262148 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define f first
#define s second
#define pb push_back
#define INF 1000000000
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef tree<
ll,
null_type,
greater<ll>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
const ll N = 1 << 20;
const int M = 20;
int dp[N][M];
set <int> st[N][M];
int gd[N];
int main()
{
freopen("bank.in", "r", stdin);
freopen("bank.out", "w", stdout);
int n, m;
cin >> n >> m;
int a[n], b[m];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
swap(n, m);
for (int i = 0; i < (1 << n); i++)
{
int kol = 0;
for (int j = 0; j < n; j++) kol += (a[i]&(1 << j)) > 0;
gd[i] = kol;
}
st[0][0].insert(0);
for (int j = 0; j < m; j++)
{
for (int i = 0; i < (1 << n); i++)
if ((n - gd[i]) >= (m - j))
{
if (st[i][j].find(a[j]) != st[i][j].end()) dp[i][j] = 1;
if (dp[i][j] > 0)
{
st[i][j + 1].insert(0);
continue;
}
for (auto g : st[i][j])
{
for (int c = 0; c < n; c++)
if (!((1 << c)&i) && g + b[c] <= a[j] && (n - gd[i + (1 << c)]) >= (m - j)) st[i + (1 << c)][j].insert(g + b[c]);
}
}
}
for (int i = 0; i <= (1 << n); i++)
if (st[i][m].find(0) != st[i][m].end()) {cout << "YES";return 0;}
cout << "NO";
}
컴파일 시 표준 에러 (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... |