이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std ;
 
#define ff first
#define ss second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ones(x) __builtin_popcount(x)
#define remove(v)  v.erase(unique(all(v)), v.end())
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define per(i, a, b) for(int i = a; i >= b; i--)
 
#ifdef local
#include "C:\debug.h"
#else
#define dbg(x...) 42
#endif
#define int long long
 
const int N = 2e6 + 2 ;
const int MOD = 1e9 + 7 ;
const int P = 1007 ;
 
int n , m , a[21] , b[21] , pref[21] ;
map<int,int> dp[21] ;
 
int go(int i , int mask , int cur) {
    if(cur == pref[i]) {
        dp[i][mask] = 1 ;
        i++ ;
    } 
    if(i > n) {
        cout << "YES\n" ;
        exit(0) ;
        return 1 ;
    }
    if(dp[i].count(mask)) return dp[i][mask] ;
    int ans = 0 ;
    rep(j , 0 , m - 1) {
        if(!(mask >> j & 1) && cur + b[j + 1] <= pref[i]) {
            ans |= go(i , (mask | (1 << j)) , cur + b[j + 1]) ;
        }
    }
    dp[i][mask] = ans ;
    return dp[i][mask] ;
}
 
void solve(){
    cin >> n >> m ;
    rep(i , 1 , n) cin >> a[i] ;
    rep(i , 1 , m) cin >> b[i] ;
    rep(i , 1 , n) pref[i] = pref[i - 1] + a[i] ;
    bool ok = go(1 , 0 , 0) ;
    cout << "NO\n" ;
}
 
signed main () {
	// ios::sync_with_stdio(false) ;
	// cin.tie(0) ;
	int test = 1 ;
	// cin >> test ; 
	for(int i = 1 ; i <= test ; i++) {
		solve() ;
	}
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'void solve()':
bank.cpp:56:10: warning: unused variable 'ok' [-Wunused-variable]
   56 |     bool ok = go(1 , 0 , 0) ;
      |          ^~| # | 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... |