# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
892813 | Faisal_Saqib | Vision Program (IOI19_vision) | C++17 | 0 ms | 0 KiB |
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 <vector>
#include <string>
using namespace std;
int add_and(std::vector<int> Ns);
int add_or(std::vector<int> Ns);
int add_xor(std::vector<int> Ns);
int add_not(int N);
bool vis[202][202];
int k,h,w;
int f(int i,int j)
{
return (i*w)+j;
}
int val=-1;
int px=-1,py=-1;
void dfs(int i,int j)
{
// cout<<"At "<<i<<' '<<j<<endl;
vis[i][j]=1;
int ox=px;
int oy=py;
px=i;
py=j;
for(int fp=-k;fp<=k;fp++)
{
int rem=k-abs(fp);
if(0<=(i+fp) and (i+fp)<h and 0<=(j+rem) and (j+rem)<w and (px!=(i+fp) or py!=(j+rem)))
{
if(val==-1)
val=add_and({f(i,j),f(i+fp,j+rem)});
else
val=add_or(val,add_and({f(i,j),f(i+fp,j+rem)}));
if(!vis[i+fp][j+rem])
dfs(i+fp,j+rem);
}
rem*=-1;
if(0<=(i+fp) and (i+fp)<h and 0<=(j+rem) and (j+rem)<w and (px!=(i+fp) or py!=(j+rem)))
{
if(val==-1)
val=add_and({f(i,j),f(i+fp,j+rem)});
else
val=add_or(val,add_and({f(i,j),f(i+fp,j+rem)}));
if(!vis[i+fp][j+rem])
dfs(i+fp,j+rem);
}
}
px=ox;
py=oy;
}
void construct_network(int H, int W, int K)
{
k=K;
h=H;
w=W;
for(int i=0;i<H;i++)
{
for(int j=0;j<W;j++)
{
if(!vis[i][j])
{
dfs(i,j);
}
}
}
}