Cod sursa(job #1368982)
Utilizator | Data | 2 martie 2015 20:57:53 | |
---|---|---|---|
Problema | Perle | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 2.36 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("perle.in");
ofstream g("perle.out");
#define NMAX 10000
int st[2][NMAX+10];
int main()
{
int t,l,v,i,niv[2],valid[2];
f>>t;
while(t--)
{
f>>l;
if(l==1)
{
f>>v;
g<<"1\n";
continue;
}
else
{
valid[1]=valid[0]=1;
niv[1]=niv[0]=1;
st[0][0]=5;
st[1][0]=6;
while(l--)
{
f>>v;
for(i=0; i<2; i++)
{
if(valid[i])
{
if(st[i][niv[i]-1]<4)
{
valid[i]=(st[i][--niv[i]]==v);
continue;
}
if(st[i][niv[i]-1]==4)
{
niv[i]--;
continue;
}
if (st[i][niv[i]-1]==5)
{
if (v == 3)
valid[i] = 0;
if (v == 1)
{
niv[i]--;
st[i][niv[i]++] = 6;
st[i][niv[i]++] = 4;
st[i][niv[i]++] = 3;
st[i][niv[i]++] = 4;
}
continue;
}
if(v==2)
niv[i]--;
if(v==1)
{
niv[i]--;
st[i][niv[i]++]=4;
st[i][niv[i]++]=2;
}
if(v==3)
{
niv[i]--;
st[i][niv[i]++]=6;
st[i][niv[i]++]=5;
}
}
if(!niv[i] && l)
valid[i]=0;
}
}
g<<((!niv[0] && valid[0]) || (!niv[1] && valid[1]))<<"\n";
}
}
return 0;
}