이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 1e9;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 12;
void solve() {
int n, m;
cin >> n >> m;
int a[n + 1], b[m], rs[1 << m], ind[1 << m];
a[n] = inf;
rs[0] = ind[0] = 0;
for(int i = 1; i < (1 << m); i++) ind[i] = rs[i] = -1;
for(int i = 0; i < n; i++) {
cin >> a[i];
}
for(int i = 0; i < m; i++) {
cin >> b[i];
}
bool ok = 0;
for(int i = 0; i < (1 << m); i++) {
if(ind[i] == n)ok = 1;
for(int j = 0; j < m; j++) {
if(i & (1 << j)) {
continue;
}
if(ind[i] == -1)continue;
int now = a[ind[i]] - rs[i] - b[j];
if(now == 0){
rs[i | (1 << j)] = 0, ind[i | (1 << j)] = ind[i] + 1;
}
else if(now > 0)rs[i | (1 << j)] = rs[i] + b[j], ind[i | (1 << j)] = ind[i];
}
}
if(ok)cout << "YES";
else cout << "NO";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int tcs = 1;
//cin >> tcs;
for(int i = 1; i <= tcs; i++) {
solve();
}
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... |