이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORU(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define IOS cin.tie(0)->sync_with_stdio(false);
#define PROB "IZhO14_bank"
void Fi(){
if(fopen(PROB".inp", "r")){
freopen(PROB".inp", "r", stdin);
freopen(PROB".out", "w", stdout);
}
}
const int N = 20;
const int V = 1000 + 1;
bool dp[1 << N][N + 1];
vector<int> adj[V];
int n, m;
int a[N], b[N];
int main(){
IOS;
Fi();
cin >> n >> m;
FORU(i, 1, n) cin >> a[i];
FOR(i, 0, m) cin >> b[i];
FOR(mask, 1, 1 << m){
int sum = 0;
FOR(i, 0, m) if(mask & (1 << i)) sum += b[i];
if(sum < N) adj[sum].eb(mask);
}
dp[0][0] = true;
FORU(i, 1, n){
FOR(mask, 1, 1 << m){
for(int s: adj[a[i]]) if((mask & s) == s){
dp[mask][i] |= dp[mask ^ s][i - 1];
}
}
}
bool ans = false;
FOR(mask, 1, 1 << m) ans |= dp[mask][n];
if(ans) cout << "YES";
else cout << "NO";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'void Fi()':
bank.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | freopen(PROB".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | freopen(PROB".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |