이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//UNSTOPPABLE
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
// #define int long long
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define pii pair<int,int>
#define sigma signed
#define tpii pair <pair <int,int> , int>
#define bruh cout << "NO\n"
using namespace std;
using namespace __gnu_pbds;
const int N = 1e3 + 5;
int mod = 1e9 + 7;
// const int INF = 1e18;
int n,m,a[N],b[N],dp[(1 << 20) + 1][21];
vector <int> g[N];
void rec(int mask , int i){
if(i == n){
cout << "YES\n";
exit(0);
}
for(auto it : g[a[i]]){
if((mask & it) == 0){
mask |= it;
rec(mask , i + 1);
mask ^= it;
}
}
}
void Goldik(){
cin >> n >> m;
for(int i = 0 ; i < n ; i++){
cin >> a[i];
}
for(int i = 0 ; i < m ; i++){
cin >> b[i];
}
for(int mask = 0 ; mask < (1 << m) ; mask++){
int sum = 0;
for(int i = 0 ; i < m ; i++){
if(((mask >> i) & 1)){
sum += b[i];
}
}
if(sum <= 1000){
g[sum].pb(mask);
}
}
// for(int i = 1 ; i <= 20 ; i++){
// cout << 5 << ' ';
// }
// cout << '\n';
rec(0 , 0);
cout << "NO\n";
}
//rewai mnogo zadach vozmozhno odna iz nih gde to popadetsya
//returning winter prime?
//chem prowe tem luchshe
sigma main(/*AZ AZDAN UZDIKSIZ*/){
//freopen("txt.in","r",stdin);
//freopen("txt.out","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
srand(time(0));
int TT = 1;
// cin >> TT;
for(int i = 1 ; i <= TT ; i++){
//cout << "Case " << i << ": ";
Goldik();
}
}
# | 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... |