이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#ifdef DEBUG
#include "debug.h"
#else
#define debug(...) void(37)
#endif
using namespace std;
#define f first
#define s second
typedef pair<int, int> pii;
signed main(){
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int N, M;
cin >> N >> M;
vector<int> people(N), money(M);
for(register int i = 0; i < N; ++i) cin >> people[i];
for(register int i = 0; i < M; ++i) cin >> money[i];
vector<pii> dp(1 << M);
dp[0] = {0, 0};
pii temp;
bool flag{false};
for(register int mask = 0; mask < (1 << M); ++mask){
if(dp[mask].f == N){ flag = true; break;}
for(register int j = 0; j < M; ++j){
if(mask & (1 << j)) continue;
if(dp[mask].s + money[j] == people[dp[mask].f]){
temp = {dp[mask].f + 1, 0};
}else{
temp = {dp[mask].f, dp[mask].s + money[j]};
}
dp[mask | (1 << j)] = max(dp[mask | (1 << j)], temp);
}
}
cout << (flag ? "YES" : "NO") << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'int main()':
bank.cpp:20:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
20 | for(register int i = 0; i < N; ++i) cin >> people[i];
| ^
bank.cpp:21:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
21 | for(register int i = 0; i < M; ++i) cin >> money[i];
| ^
bank.cpp:26:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
26 | for(register int mask = 0; mask < (1 << M); ++mask){
| ^~~~
bank.cpp:28:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
28 | for(register int j = 0; j < M; ++j){
| ^
# | 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... |