#include "vision.h"
#include <bits/stdc++.h>
using namespace std;
void construct_network(int h, int w, int k) {
if (h*w==2) {
if (k==1) add_and({0,1});
else add_xor({0,1});
return;
}
int zero = add_and({0,1,2});
int one = add_not(zero);
vector<int> row(h,0);
vector<int> col(w,0);
for (int i=0; i<h; ++i) {
vector<int> a;
for (int j=0; j<w; ++j) {
a.push_back(i*w+j);
}
row[i]=add_xor(a);
}
for (int j=0; j<w; ++j) {
vector<int> a;
for (int i=0; i<h; ++i) {
a.push_back(i*w+j);
}
col[j]=add_xor(a);
}
int _check1 = add_or(row), _check2 = add_or(col);
int check1 = add_not(_check1), check2 = add_not(_check2);
vector<int> row_k={zero}, col_k={zero};
for (int j=0; j+k<w; ++j) col_k.push_back(add_and({col[j],col[j+k]}));
for (int i=0; i+k<h; ++i) row_k.push_back(add_and({row[i],row[i+k]}));
int _a1=add_or(col_k), _a2=add_or(row_k);
int inSameRow=add_and({check1,_a1}), inSameCol=add_and({check2,_a2});
vector<int> prefRow, sufRow, prefCol, sufCol;
prefRow={row[0]};
for (int i=1; i<h; ++i) {
prefRow.push_back(add_xor({row[i],prefRow[i-1]}));
}
sufRow={row[h-1]};
for (int i=h-2; i>=0; --i) {
sufRow.push_back(add_xor({row[i],sufRow[h-2-i]}));
}
prefCol={col[0]};
for (int i=1; i<w; ++i) {
prefCol.push_back(add_xor({col[i],prefCol[i-1]}));
}
sufCol={col[w-1]};
for (int i=w-2; i>=0; --i) {
sufCol.push_back(add_xor({col[i],sufCol[w-2-i]}));
}
vector<int> bitxl, bityl, bitxr, bityr;
vector<int> rl(h), cl(w), rr(h), cr(w);
for (int i=0; i<h; ++i) {
//cout<<"PrefRow\n";
int p=add_and({i?prefRow[i-1]:zero,(i<(h-1))?prefRow[i+1]:zero});
int q=add_xor({p,prefRow[i],i?prefRow[i-1]:zero});
int t=add_not(p);
rl[i]=add_and({q,prefRow[i],t});
}
for (int i=0; i<h; ++i) {
//cout<<"SufRow\n";
int p=add_and({i?sufRow[i-1]:zero,(i<(h-1))?sufRow[i+1]:zero});
int q=add_xor({p,sufRow[i],i?sufRow[i-1]:zero});
int t=add_not(p);
rr[h-1-i]=add_and({q,sufRow[i],t});
}
for (int i=0; i<w; ++i) {
//cout<<"PrefCol\n";
int p=add_and({i?prefCol[i-1]:zero,(i<(w-1))?prefCol[i+1]:zero});
int q=add_xor({p,prefCol[i],i?prefCol[i-1]:zero});
int t=add_not(p);
cl[i]=add_and({q,prefCol[i],t});
}
for (int i=0; i<w; ++i) {
//cout<<"SufCol\n";
int p=add_and({i?sufCol[i-1]:zero,(i<(w-1))?sufCol[i+1]:zero});
int q=add_xor({p,sufCol[i],i?sufCol[i-1]:zero});
int t=add_not(p);
cr[w-1-i]=add_and({q,sufCol[i],t});
}
for (int i=0; i<10; ++i) {
vector<int> a={zero};
for (int x=0; x<h; ++x) {
if ((x>>i) & 1) a.push_back(rl[x]);
}
bitxl.push_back(add_or(a));
} //for (auto x:bitxl) cout<<x<<' '; cout<<'\n';
for (int i=0; i<10; ++i) {
vector<int> a={zero};
for (int x=0; x<w; ++x) {
if ((x>>i) & 1) a.push_back(cl[x]);
}
bityl.push_back(add_or(a));
} //for (auto x:bityl) cout<<x<<' '; cout<<'\n';
for (int i=0; i<10; ++i) {
vector<int> a={zero};
for (int x=0; x<h; ++x) {
if ((x>>i) & 1) a.push_back(rr[x]);
}
bitxr.push_back(add_or(a));
} //for (auto x:bitxr) cout<<x<<' '; cout<<'\n';
for (int i=0; i<10; ++i) {
vector<int> a={zero};
for (int x=0; x<w; ++x) {
if ((x>>i) & 1) a.push_back(cr[x]);
}
bityr.push_back(add_or(a));
} //for (auto x:bityr) cout<<x<<' '; cout<<'\n';
vector<int> xorx(10,zero),xory(10,zero),ansbitx(10,zero),ansbity(10,zero),ansbit(10,zero);
for (int i=0; i<10; ++i) {
xorx[i]=add_xor({bitxl[i],bitxr[i]});
}
for (int i=0; i<10; ++i) {
xory[i]=add_xor({bityl[i],bityr[i]});
}
ansbitx[0]=xorx[0];
ansbity[0]=xory[0];
int buffer=add_and({bitxr[0],bitxl[0]});
for (int i=1; i<10; ++i) {
ansbitx[i]=add_xor({xorx[i],buffer});
int p=add_and({bitxr[i],bitxl[i]});
int q=add_and({buffer,xorx[i]});
buffer=add_or({p,q});
} //for (auto x:ansbitx) cout<<x<<' '; cout<<'\n';
buffer=add_and({bityr[0],bityl[0]});
for (int i=1; i<10; ++i) {
ansbity[i]=add_xor({xory[i],buffer});
int p=add_and({bityr[i],bityl[i]});
int q=add_and({buffer,xory[i]});
buffer=add_or({p,q});
} //for (auto x:ansbity) cout<<x<<' '; cout<<'\n';
vector<int> xorans(10,zero);
for (int i=0; i<10; ++i) xorans[i]=add_xor({ansbity[i],ansbitx[i]});
ansbit[0]=xorans[0];
for (int i=1; i<10; ++i) {
int p=add_and({ansbitx[i-1],ansbity[i-1]});
int q=add_or({ansbitx[i-1],ansbity[i-1]});
int t=add_xor({q,ansbit[i-1]});
int z=add_and({t,q});
int o=add_or({p,z});
ansbit[i]=add_xor({xorans[i],o});
}
vector<int> forans;
for (int i=0; i<10; ++i) {
if (k&(1<<i)) forans.push_back(ansbit[i]);
else {
int v=add_not(ansbit[i]);
forans.push_back(v);
}
}
int ans=add_and(forans);
add_or({ans,inSameCol,inSameRow});
}
Compilation message
vision.cpp: In function 'void construct_network(int, int, int)':
vision.cpp:14:6: warning: unused variable 'one' [-Wunused-variable]
14 | int one = add_not(zero);
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Incorrect |
0 ms |
212 KB |
on inputs (0, 2), (1, 1), expected 1, but computed 0 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Incorrect |
0 ms |
212 KB |
on inputs (0, 2), (1, 1), expected 1, but computed 0 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Incorrect |
0 ms |
212 KB |
on inputs (0, 2), (1, 1), expected 1, but computed 0 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Incorrect |
0 ms |
212 KB |
on inputs (0, 2), (1, 1), expected 1, but computed 0 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Incorrect |
2 ms |
596 KB |
on inputs (0, 49), (0, 50), expected 0, but computed 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
596 KB |
Output is correct |
13 |
Correct |
2 ms |
544 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
6 ms |
980 KB |
Output is correct |
21 |
Correct |
7 ms |
948 KB |
Output is correct |
22 |
Correct |
6 ms |
980 KB |
Output is correct |
23 |
Correct |
5 ms |
972 KB |
Output is correct |
24 |
Correct |
6 ms |
980 KB |
Output is correct |
25 |
Correct |
5 ms |
980 KB |
Output is correct |
26 |
Correct |
5 ms |
980 KB |
Output is correct |
27 |
Correct |
10 ms |
1488 KB |
Output is correct |
28 |
Correct |
10 ms |
1488 KB |
Output is correct |
29 |
Correct |
10 ms |
1488 KB |
Output is correct |
30 |
Correct |
10 ms |
1488 KB |
Output is correct |
31 |
Correct |
13 ms |
1488 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1488 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
6 ms |
964 KB |
Output is correct |
8 |
Correct |
5 ms |
980 KB |
Output is correct |
9 |
Correct |
12 ms |
1468 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Incorrect |
0 ms |
212 KB |
on inputs (0, 2), (1, 1), expected 1, but computed 0 |
9 |
Halted |
0 ms |
0 KB |
- |