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>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
int h, w, k;
vector<int> allvals;
void calchor(int nl, int nr, int ml, int mr){
if(ml == mr) return;
int nm = (nl+nr)/2;
int mm = (ml+mr)/2;
vector<int> vec1, vec2;
//cout << "vec1\n";
for(int i = nl; i <= nm; ++i)
for(int j = ml; j <= mm; ++j){
vec1.pb(i*w+j);
//cout << i << ' ' << j << '\n';
}
//cout << "vec2\n";
for(int i = nm+1; i <= nr; ++i)
for(int j = mm+1; j <= mr; ++j){
vec2.pb(i*w+j);
//cout << i << ' ' << j << '\n';
}
//cout << '\n';
if(vec1.size() && vec2.size())
allvals.pb(add_and({add_or(vec1), add_or(vec2)}));
calchor(nl, nr, ml, mm);
calchor(nl, nr, mm+1, mr);
}
void calcvert(int nl, int nr, int ml, int mr){
if(nl == nr) return;
calchor(nl, nr, ml, mr);
int nm = (nl+nr)/2;
calcvert(nl, nm, ml, mr);
calcvert(nm+1, nr, ml, mr);
}
void construct_network(int H, int W, int K) {
h = H;
w = W;
k = K;
allvals.clear();
calcvert(0, H-1, 0, W-1);
map<int, vector<int>> diapos;
map<int, vector<int>> dianeg;
for(int i = 0; i < H; ++i)
for(int j = 0; j < W; ++j){
diapos[i+j].pb(i*W+j);
dianeg[i-j].pb(i*W+j);
}
for(auto & u : diapos)
u.ss.pb(add_or(u.ss));
for(auto & u : dianeg)
u.ss.pb(add_or(u.ss));
vector<int> v1;
for(auto u : diapos)
if(u.ss.size() && diapos[u.ff+K].size())
v1.pb( add_and( {u.ss.back(), diapos[u.ff+K].back()} ) );
assert(v1.size());
int samepos = add_or(v1);
vector<int> v2;
for(auto u : dianeg)
if(u.ss.size() && dianeg[u.ff+K].size())
v2.pb( add_and( {u.ss.back(), dianeg[u.ff+K].back()} ) );
assert(v2.size());
int sameneg = add_or(v2);
if(allvals.empty()){
add_and({sameneg});
}
else{
int ispos = add_or(allvals);
add_or({add_and({ispos, samepos}), add_and({add_not(ispos), sameneg})});
}
}
# | 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... |