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;
typedef vector<int> vi;
int W,H,K;
int nMEM, nDIAG, nDIF, nBAND;
int memory(int x, int y) {return x+W*y;}
int diag1(int i) {return nMEM+i +1;}
int diag2(int i) {return diag1(nDIAG) +i;}
int dif1(int i) {return diag2(nDIAG) +i;}
int dif2(int i) {return dif1(nDIF) +i;}
int band1(int i) {return dif2(nDIF) +i;}
int band2(int i) {return band1(nBAND) +i;}
void construct_network(int h, int w, int k) {
W=w;
H=h;
K=k;
nMEM=W*H;
nDIAG=W+H-1;
nDIF=nDIAG-K;
nBAND=nDIF;
vi Ns;
int always_false=add_xor({0,0});
//cout << "diag1\n";
//diag1
int startx,starty;
for(int i=0; i<nDIAG; i++) {
Ns={};
starty=H-1-i;
startx=0-min(0,starty);
starty=max(0,starty);
for(int j=0; startx+j<W and starty+j<H; j++)
Ns.push_back(memory(startx+j, starty+j));
add_or(Ns);
}
//cout << "diag2\n";
//diag2
for(int i=0; i<nDIAG; i++) {
Ns={};
starty=H-1-i;
startx=W-1+min(0,starty);
starty=max(0,starty);
for(int j=0; startx-j>=0 and starty+j<H; j++)
Ns.push_back(memory(startx-j, starty+j));
add_or(Ns);
}
//cout << "dif1\n";
//dif1
for(int i=0; i<nDIF; i++) {
Ns={diag1(i),diag1(i+K)};
add_and(Ns);
}
//cout << "dif2\n";
//dif2
for(int i=0; i<nDIF; i++) {
Ns={diag2(i),diag2(i+K)};
add_and(Ns);
}
//cout << "band1\n";
//band1
for(int i=0; i<nBAND; i++) {
Ns={always_false};
for(int j=-1; i+j>=0; j--) Ns.push_back(diag1(i+j));
for(int j=K+1; i+j<nBAND; j++) Ns.push_back(diag1(i+j));
add_or(Ns); // add not(and(band))
}
//cout << "band2\n";
//band2
for(int i=0; i<nBAND; i++) {
Ns={always_false};
for(int j=-1; i+j>=0; j--) Ns.push_back(diag2(i+j));
for(int j=K+1; i+j<nBAND; j++) Ns.push_back(diag2(i+j));
add_or(Ns); // add not(and(band))
}
//cout << "dif1 or\n";
//or for dif1
Ns={};
for(int i=0; i<nDIF; i++) Ns.push_back(dif1(i));
int or_dif1=add_or(Ns);
//cout << "dif2 or\n";
//or for dif2
Ns={};
for(int i=0; i<nDIF; i++) Ns.push_back(dif2(i));
int or_dif2=add_or(Ns);
//cout << "band1 or\n";
//not and band1
Ns={};
for(int i=0; i<nBAND; i++) Ns.push_back(band1(i));
int or_band1=add_not(add_and(Ns));
//cout << "band2 or\n";
//not and band1
Ns={};
for(int i=0; i<nBAND; i++) Ns.push_back(band2(i));
int or_band2=add_not(add_and(Ns));
//cout << "final\n";
add_or({add_and({or_dif1,or_band2}), add_and({or_dif2,or_band1})});
}
# | 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... |