| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1312648 | coderg | 은행 (IZhO14_bank) | C++20 | 79 ms | 8612 KiB |
#include "bits/stdc++.h"
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define pb push_back
void setIO(string name = ""){if(name.size()){ freopen((name + ".in").c_str(), "r", stdin);freopen((name + ".out").c_str(), "w", stdout);}}
#define F(i,l,r) for(int i=(l);i<(r);++i)
#define FR(i,l,r) for(int i=(l);i>=(r);--i)
typedef long long ll;
const int maxn=(1<<20);
const int mod=1e9+7;
const int mox=2000*500+505;
const int inf=1e9;
int a[25],dp[maxn],sum[maxn],b[25],pref[25];
void solve(){
int n,m;
cin>>n>>m;
F(i,0,n)cin>>a[i];
F(i,0,m)cin>>b[i];
pref[0]=0;
F(i,0,n)pref[i+1]=pref[i]+a[i];
fill(dp,dp+(1<<m),-1);
dp[0]=sum[0]=0;
F(mask,0,(1<<m)){
if(dp[mask]==-1)continue;
int k=dp[mask];
if(k==n){
yes;
return;
}
int cur=sum[mask],needed=pref[k];
int partial=cur-needed,target=a[k];
F(j,0,m){
if(!((mask>>j)&1)){
int nxt=mask|(1<<j),bill=b[j];
sum[nxt]=cur+bill;
if(partial+bill<target)dp[nxt]=max(dp[nxt],k);
else if(partial+bill==target)dp[nxt]=max(dp[nxt],k+1);
}
}
}
no;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(nullptr);
// setIO("bank");
int tt=1;
// cin>>tt;
while(tt--)solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 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... | ||||
