This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Problem: Elevator Rides
// #pragma GCC optimize("O3")
// #pragma GCC target("avx2")
#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] , p[21] ;
int dp[1048577] ;
void solve(){
p[0] = 1 ;
rep(i , 1 , 20) p[i] = p[i - 1] * P , p[i] %= MOD ;
cin >> n >> m ;
int hash = 0 ;
rep(i , 1 , n) cin >> a[i] ;
sort(a + 1 , a + 1 + n) ;
rep(i , 1 , n) {
int cur = (a[i] * (p[i] % MOD)) % MOD ;
hash += cur ; hash %= MOD ;
}
set<int> w(a + 1 , a + 1 + n) ;
rep(i , 1 , m) cin >> b[i] ;
set<pair<int,int>> e ;
rep(i , 1 , (1 << m) - 1) {
int cur = 0 ;
rep(mask , 0 , m - 1) {
if((i >> mask) & 1) {
cur += b[mask + 1] ;
}
}
if(cur <= 1000 && w.count(cur)) e.insert({i , cur}) ;
}
vector<pair<int,int>> item(all(e)) ;
int sz = sz(item) ;
rep(i , 0 , (1 << sz) - 1) {
vector<int> v ;
int cur = 0 ;
bool ok = 1 ;
rep(mask , 0 , sz - 1) {
if((i >> mask & 1)) {
int x = ones(cur) ;
int y = ones(item[mask].first) ;
cur ^= item[mask].first ;
if(x + y != ones(cur)) {
ok = 0 ;
break ;
}
v.pb(item[mask].second) ;
}
}
sort(all(v)) ;
int H = 0 , id = 0 ;
for(auto& x : v) {
id++ ;
int add = (x * (p[id] % MOD)) % MOD ;
H += add ; H %= MOD ;
}
if(H == hash) {
cout << "YES\n" ;
return ;
}
}
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() ;
}
}
Compilation message (stderr)
bank.cpp: In function 'void solve()':
bank.cpp:63:14: warning: variable 'ok' set but not used [-Wunused-but-set-variable]
63 | bool ok = 1 ;
| ^~| # | 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... |