이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fr first
#define se second
#define rep(i,a,b) for(int i = a; i < (b); ++i)
#define rrep(i,a,b) for(int i = a; i > (b); --i)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define IN(i,l,r) (l<i&&i<r)
#define pb push_back
#define ones __builtin_popcountll
using namespace std;
using namespace __gnu_pbds;
template <class T>
using OSTree = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef long long ll;
const int U = 20;
int main(){
cin.tie(0)->sync_with_stdio(false);
int n,m; cin >> n >> m;
vi a(n), b(m);
rep(i,0,n) cin >> a[i];
rep(i,0,m) cin >> b[i];
vll dp(1<<U,-1), remcash(1<<U,-1);
dp[0] = 0;
remcash[0] = 0;
bool flag = false;
rep(i,1,1<<m){
rep(j,0,m){
if(i&(1<<j) == 0) continue;
int z = i ^ (1<<j);
if(dp[z] < 0) continue;
if(remcash[z] + b[j] < a[dp[z]]){
dp[i] = dp[z];
remcash[i] = remcash[z] + b[j];
}else if(remcash[z] + b[j] == a[dp[z]]){
dp[i] = dp[z] + 1;
remcash[i] = 0;
}
}
if(dp[i] == n){
flag = true; break;
}
}
cout << (flag ? "YES" : "NO") << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'int main()':
bank.cpp:34:25: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
34 | if(i&(1<<j) == 0) continue;
| ~~~~~~~^~~~
# | 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... |