This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "vision.h"
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define SZ(x) int((x).size())
#define sep ' '
const int MOD = 1e9 + 7;
const int LOG = 9;
int n , m , k;
vector<int> all;
int count_bits(int x){
int res = 0;
while(x){
res++;
x /= 2;
}
return res;
}
vector<int> solve(int l , int r){
vector<int> bits , nots;
int lg = count_bits(r - l);
for(int i = 0 ; i < lg ; i++){
int sz = (1 << i);
vector<int> ns;
for(int j = l ; j <= r ; j++){
vector<int> query;
for(int k = j ; k <= r ; k++){
if((k - j) & (1 << i)){
query.push_back(k);
}
}
if(SZ(query) == 0) continue;
int OR = add_or(query);
query = {OR , j};
ns.push_back(add_and(query));
}
bits.push_back(add_or(ns));
nots.push_back(add_not(bits.back()));
}
vector<int> res;
for(int i = 0 ; i < min((1 << lg) , k + 1) ; i++){
vector<int> ns;
for(int j = 0 ; j < lg ; j++){
if(i & (1 << j)){
ns.push_back(bits[j]);
}
else{
ns.push_back(nots[j]);
}
}
if(SZ(ns) == 0){
res.push_back(add_or(all));
continue;
}
res.push_back(add_and(ns));
}
return res;
}
void construct_network(int H, int W, int K) {
n = H; m = W; k = K;
int mn = MOD , mx = -MOD;
for(int i = 0 ; i < n ; i++){
vector<int> ns;
for(int j = 0 ; j < m ; j++){
ns.push_back(i * m + j);
all.push_back(i * m + j);
}
int ind = add_or(ns);
mn = min(mn , ind);
mx = max(mx , ind);
}
vector<int> A = solve(mn , mx);
mn = MOD, mx = -MOD;
for(int i = 0 ; i < m ; i++){
vector<int> ns;
for(int j = 0 ; j < n ; j++){
ns.push_back(j * m + i);
}
int ind = add_or(ns);
mn = min(mn , ind);
mx = max(mx , ind);
}
vector<int> B = solve(mn , mx);
//assert(SZ(A) == k + 1);
//assert(SZ(B) == k + 1);
vector<int> ns;
for(int i = 0 ; i < SZ(A) ; i++){
for(int j = 0 ; j < SZ(B) ; j++){
if(i + j != k) continue;
vector<int> query = {A[i] , B[j]};
ns.push_back(add_and(query));
}
}
add_or(ns);
}
Compilation message (stderr)
vision.cpp: In function 'std::vector<int> solve(int, int)':
vision.cpp:28:7: warning: unused variable 'sz' [-Wunused-variable]
28 | int sz = (1 << i);
| ^~
# | 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... |
# | 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... |