이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,l,r) for(int i = (l); i < r; i++)
#define per(i,r,l) for(int i = (r); i >= l; i--)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define ss second
const ll mod = 1e9 + 7, maxn = 20, inf = 1e9 + 5;
int a[maxn], c[maxn];
pair<int, int> dp[1 << maxn];
int main(){
int n, m; cin >> n >> m;
rep(i,0,n) cin >> a[i];
rep(i,0,m) cin >> c[i];
dp[0] = {0, 0};
rep(b, 1, 1 << m){
rep(i,0,m){
pair<int, int> df;
if((b & (1 << i)) && dp[b ^ (1 << i)].ff != -1){
int t = a[dp[(b ^ (1 << i))].ff] - dp[(b^(1 << i))].ss;
if(t < c[i]) continue;
dp[b] = dp[(b ^ (1 << i))];
if(t == c[i]){
dp[b].ff++;
dp[b].ss = 0;
if(dp[b].ff == n) return cout << "YES\n", 0;
}else{
dp[b].ss += c[i];
}
break;
}
dp[b].ff = -1;
}
}
// rep(i,0,1 << m){
// rep(j,0,m) cout << (i & (1 << j) ? 1 : 0);
// cout << ' ' << i << ' ' << dp[i].ff << ' ' << dp[i].ss << '\n';
// }
cout << "NO\n";
return 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... |