제출 #1128182

#제출 시각아이디문제언어결과실행 시간메모리
1128182colfp은행 (IZhO14_bank)C++20
100 / 100
118 ms8644 KiB
#include<bits/stdc++.h> using namespace std; int a[30],b[30]; int arr[(1<<20)],dp[(1<<20)]; int n,m; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for(int i = 1; i <= n; i++) { cin >> a[i]; } for(int i = 0; i < m; i++) { cin >> b[i]; } for(int i = 1; i < (1 << m);i++) { for(int j = 0; j < m; j++) { if(!(i & (1 << j))) { continue; } int msk = i^(1<<j); int cur = dp[msk]+1; int cash = arr[msk]; if(cur <= dp[i]) { continue; } if(a[cur] == cash + b[j]) { dp[i] = cur; arr[i] = 0; } else if(dp[msk] >= dp[i]) { dp[i] = dp[msk]; arr[i] = arr[msk] + b[j]; } } if(dp[i] == n) { cout << "YES"; return 0; } } cout << "NO"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...