제출 #497205

#제출 시각아이디문제언어결과실행 시간메모리
497205tphuc2908은행 (IZhO14_bank)C++14
71 / 100
1080 ms6176 KiB
#include <bits/stdc++.h>

using namespace std;
#define rep(i,x,y) for(int i = x; i <= y; ++i)
#define repi(i,x,y) for(int i = x; i >= y; --i)
#define fi first
#define se second
#define ci(x) int x; cin >> x
#define cii(x,y) int x, y; cin >> x >> y
#define ciii(x,y,z) int x,y,z; cin >> x >> y >> z
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
//#define int long long
typedef long long ll;
const int N = 5e5 + 5;
const int mod = 1e9 + 7;
const int mod1 = 1e9 + 9;
const int pi = 23;
const ll inf = 1e18 + 5;

void read_file(){
    freopen("text.inp", "r", stdin);
//    freopen("SEARCHING.INP" , "r", stdin);
//    freopen("SEARCHING.OUT", "w", stdout);
}

/*
    dp[bit][i] is the subset of M so that you can pay for first i members
    enumerate subset of subset in 3^n for sub 1,2,3
*/

int n, m;
int a[N], b[N];
int dp[(1<<20) + 5][25];

void inp(){
    cin >> n >> m;
    rep(i,1,n) cin >> a[i];
    rep(i,0,m-1) cin >> b[i];
}

int sum[(1<<20) + 5];

void process(){
    rep(i,0,(1<<m)-1)
        for(int j = 0; j < m; ++j)
            if((i>>j)&1)
                sum[i] += b[j];
    if(n==1){
        bool ok = 0;
        rep(i,0,(1<<m)-1)
            if(sum[i]==a[1]){
                ok = 1;
                break;
            }
        if(ok) cout << "YES";
        else cout << "NO";
        return;
    }
    dp[0][0] = 1;
    rep(i,1,(1<<m)-1){
        for(int t = i; t; t = (t-1)&i){
            rep(j,1,n){
                int s = sum[t];
                if(s==a[j] && dp[i^t][j-1]){
                    if(i==63)
                        int h = 0;
                    dp[i][j] = 1;
                }
            }
        }
    }
    bool ok = 0;
    rep(i,0,(1<<m)-1)
        if(dp[i][n]){
            ok = 1;
            break;
        }
    if(ok) cout << "YES";
    else cout << "NO";
}

int main()
{
    //read_file();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    inp();
    process();
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

bank.cpp: In function 'void process()':
bank.cpp:68:29: warning: unused variable 'h' [-Wunused-variable]
   68 |                         int h = 0;
      |                             ^
bank.cpp: In function 'void read_file()':
bank.cpp:23:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     freopen("text.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...