이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Nguyen Huu Hoang Minh
#include <bits/stdc++.h>
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define reset(x) memset(x, 0,sizeof(x))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define N 25
#define remain(x) if (x > MOD) x -= MOD
#define ii pair<int, int>
#define iiii pair< ii , ii >
#define viiii vector< iiii >
#define vi vector<int>
#define vii vector< ii >
#define bit(x, i) (((x) >> (i)) & 1)
#define Task "test"
#define int long long
using namespace std;
typedef long double ld;
const int inf = 1e10;
const int minf = -1e10;
int n, m;
int pp[N], s[N];
void readfile()
{
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
if (fopen(Task".inp","r"))
{
freopen(Task".inp","r",stdin);
//freopen(Task".out","w",stdout);
}
cin >> n >> m;
for(int i=0; i<n; i++) cin >> pp[i];
for(int i=0; i<m; i++) cin >> s[i];
}
int dp[1<<20];
int lef[1<<20];
void proc()
{
memset(dp, -1, sizeof dp);
memset(lef, -1, sizeof lef);
dp[0] = 0;
lef[0] = 0;
int mm = (1<<m);
for(int msk = 0; msk < mm; msk++){
for(int i=0; i<m; i++){
if (msk&(1<<i) == 0) continue;
int pre = msk^(1<<i);
if (dp[pre]==-1) continue;
int new_amt = lef[pre]+s[i];
int cur_tar = pp[dp[pre]];
if (new_amt < cur_tar){
lef[msk] = new_amt;
dp[msk] = dp[pre];
}
else if (new_amt == cur_tar){
lef[msk] = 0;
dp[msk] = dp[pre]+1;
}
}
if (dp[msk]==n){
cout << "YES";
return;
}
}
cout<<"NO";
}
signed main()
{
readfile();
proc();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'void proc()':
bank.cpp:56:28: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
56 | if (msk&(1<<i) == 0) continue;
| ~~~~~~~^~~~
bank.cpp: In function 'void readfile()':
bank.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | freopen(Task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | 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... |