# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
111979 | AMO5 | Memory 2 (JOI16_memory2) | C++98 | 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 "Memory2_lib.h"
void Solve(int T, int N){
int p[1011],visit[1011];
int adj[55][55];
vector < pair < int, pii> > pos[55];
if(T==1)
{
int n = N*2;
memset(p,0,sizeof(p));
for(int i = 1; i <= n; i++)
{
for(int j = i+1; j <= n; j++)
{
int x = Flip(i,j);
adj[i-1][j-1] = x;
adj[j-1][i-1] = x;
}
}
for(int i = 0; i < n; i++)
{
for(int j = i+1; j < n; j++)
{
for(int k = j+1; k < n; k++)
{
if(adj[i][j]==adj[i][k]&&adj[i][j]==adj[j][k])
{
int curr = adj[i][j];
pos[curr].pb(mp(i,mp(j,k)));
//cout << adj[i][j] << " " << i << " " << j << " " << k << endl;
}
}
}
}
/*
cout << "***" << endl;
for(int i = 0; i <= 50; i++)
{
if(pos[i].empty())continue;
cout << i << endl;
for(int j = 0; j < pos[i].size(); j++)
{
cout << pos[i][j].fi << " " << pos[i][j].se.fi << " " << pos[i][j].se.se << endl;
}
cout << endl;
}
cout << "***" << endl;
*/
int pos1(-1),pos2(-1);
for(int i = 0; i <= 50; i++)
{
pos1 = -1;
if(pos[i].empty())continue;
int vis[n];
memset(vis,0,sizeof(vis));
//cout << i << " ";
for(int j = 0; j < 2; j++)
{
//cout << pos[i][j].fi << " " << pos[i][j].se.fi << " " << pos[i][j].se.se << " ";
if(!vis[pos[i][j].fi])
{
vis[pos[i][j].fi] = 1;
}
else
{
if(pos1==-1)pos1 = pos[i][j].fi;
else pos2 = pos[i][j].fi;
}
if(!vis[pos[i][j].se.fi])
{
vis[pos[i][j].se.fi] = 1;
}
else
{
if(pos1==-1)pos1 = pos[i][j].se.fi;
else pos2 = pos[i][j].se.fi;
}
if(!vis[pos[i][j].se.se])
{
vis[pos[i][j].se.se] = 1;
}
else
{
if(pos1==-1)pos1 = pos[i][j].se.se;
else pos2 = pos[i][j].se.se;
}
}
//cout << endl;
//cout << " ~ " << pos1 << " " << pos2 << endl;
Answer(pos1,pos2,i);
visit[pos1] = 1;
visit[pos2] = 1;
}
pos1 = -1, pos2 = -1;
for(int i = 0; i < n; i++)
{
if(visit[i]==0)
{
if(pos1==-1)pos1 = i;
else
{
pos2 = i;
break;
}
}
}
Answer(pos1,pos2,n/2-1);
//for(int i = 0; i < n; i++)cout << p[i] << " " ;
//cout << endl;
}
return;
}