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 int long long
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
using namespace std;
int N,M;
inline int get_ind(int a,int b){
return a*M+b;
}
inline bool is_valid(int a,int b){
return a>=0 && a<N && b>=0 && b<M;
}
void construct_network(int n, int m, int k){
N=n,M=m;
if(k==1){
vector<int> query;
int bl=0,wh=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if((i+j)&1) bl++;
else wh++;
}
}
if(bl<=wh){
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(!((i+j)&1)) continue;
vector<int> sor;
if(is_valid(i+1,j)) sor.push_back(get_ind(i+1,j));
if(is_valid(i-1,j)) sor.push_back(get_ind(i-1,j));
if(is_valid(i,j+1)) sor.push_back(get_ind(i,j+1));
if(is_valid(i,j-1)) sor.push_back(get_ind(i,j-1));
vector<int> xd;
xd.push_back(get_ind(i,j));
xd.push_back(add_or(sor));
query.push_back(add_and(xd));
}
}
}
else{
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if((i+j)&1) continue;
vector<int> sor;
if(is_valid(i+1,j)) sor.push_back(get_ind(i+1,j));
if(is_valid(i-1,j)) sor.push_back(get_ind(i-1,j));
if(is_valid(i,j+1)) sor.push_back(get_ind(i,j+1));
if(is_valid(i,j-1)) sor.push_back(get_ind(i,j-1));
vector<int> xd;
xd.push_back(get_ind(i,j));
xd.push_back(add_or(sor));
query.push_back(add_and(xd));
}
}
}
add_or(query);
return;
}
if(max(n,m)<=30){
vector<int> query;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
vector<int> sor;
int a = i, b = j + k;
for(int u=0;u<max(N,M);u++){
if(is_valid(a,b) && abs(a-i)+abs(b-j)==k) sor.push_back(get_ind(a,b));
a++,b--;
}
a = i, b = j - k;
for(int u=0;u<max(N,M);u++){
if(is_valid(a,b) && abs(a-i)+abs(b-j)==k) sor.push_back(get_ind(a,b));
a++,b++;
}
if(sor.empty()) continue;
vector<int> xd;
xd.push_back(get_ind(i,j));
xd.push_back(add_or(sor));
query.push_back(add_and(xd));
}
}
add_or(query);
return;
}
if(min(n,m)!=1){
vector<int> query;
int a = 0, b = k;
for(int u=0;u<max(N,M);u++){
if(is_valid(a,b)){
vector<int> xd;
xd.push_back(get_ind(0,0));
xd.push_back(get_ind(a,b));
query.push_back(add_and(xd));
}
a++,b--;
}
add_or(query);
return;
}
if(n==1){
vector<int> query;
for(int i=0;i+k<m;i++){
vector<int> xd;
xd.push_back(i);
xd.push_back(i+k);
query.push_back(add_and(xd));
}
add_or(query);
}
else{
vector<int> query;
for(int i=0;i+k<n;i++){
vector<int> xd;
xd.push_back(i);
xd.push_back(i+k);
query.push_back(add_and(xd));
}
add_or(query);
}
}
# | 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... |