is_subset
bool is_subset(ll a, ll b){
ll c = (~b | a);
if(c==~0LL){
return true;
}else{
return false;
}
}
A. Marcin and Training Camp
- Quiz
- AC
- 解説
- editorialの通り。N=7000なので7000x7000x60だとTLE
- bitで見たときにbがaのsubsetである判定をO(1)でする必要がある
bool is_subset(ll a, ll b){
ll c = (~b | a);
if(c==~0LL){
return true;
}else{
return false;
}
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin>>N;
VI A(N);
rep(i,N)cin>>A[i];
VI B(N);
rep(i,N)cin>>B[i];
map<ll, VI> mp;
rep(i,N){
mp[A[i]].push_back(B[i]);
}
map<ll,bool> used;
ll sum=0;
VI M;
for(auto pa : mp){
if(pa.second.size()==1) continue;
ll a = pa.first;
sum += SUM(pa.second);
M.push_back(a);
used[a]=true;
}
rep(i,N){
ll a = A[i];
if(used[a]) continue;
bool humble = false;
for(ll v : M){
if(is_subset(v, a)) humble=true;
}
if(humble) sum+=B[i];
}
p(sum);
return 0;
}