이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define TASK "Bank"
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define READFILE freopen(TASK".INP","r",stdin)
#define WRITEFILE freopen(TASK".OUT","w",stdout)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rep(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define ENDL '\n'
#define debug(x) cout<<#x<<" = "<<x<<ENDL
#define fi first
#define se second
#define ever (;true;)
#define all(x) x.begin(),x.end()
#define sz(a) ((int)(a).size())
#define ms(a,x) memset(a,x,sizeof(a))
#define int long long
using namespace std;
typedef vector <int> vi;
typedef pair <int,int> ii;
typedef vector <ii> vpi;
typedef pair <int,ii> iii;
const int N = 25;
const int oo=0x3f;
const int mod=1e9+7;
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
int a[N], cost[N];
ii dp[(1<<20)+5];
bool cmp(ii a, ii b){
return (a.fi<b.fi || a.fi==b.fi && a.se<b.se);
}
signed main()
{
FAST;
int n,m;
cin >> n >> m;
For(i,1,n) cin >> a[i];
For(i,1,m) cin >> cost[i];
int mm=1<<m;
for (int mask=0; mask<mm; mask++){
For(i,0,m-1){
if ((mask>>i)&1){
ii p=dp[mask^(1<<i)];
if (p.se+cost[i+1]==a[p.fi+1]){
{
dp[mask]={p.fi+1,0};
}
}
else dp[mask]=max(dp[mask],{p.fi,p.se+cost[i+1]});
}
}
}
if (dp[mm-1].fi==n) {
cout << "YES" ;
} else cout << "NO";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'bool cmp(ii, ii)':
bank.cpp:32:37: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
32 | return (a.fi<b.fi || a.fi==b.fi && a.se<b.se);
| ^
# | 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... |