QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#825861#9769. Rolling Stonesucup-team4074#AC ✓2ms4556kbC++172.7kb2024-12-21 23:46:282024-12-21 23:46:28

Judging History

你现在查看的是最新测评结果

  • [2024-12-21 23:46:28]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:4556kb
  • [2024-12-21 23:46:28]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=210;
struct A{int i,j,a,b;
};
int d[maxn][maxn][4];
int a[maxn][maxn];
void solve();
int n,s1,s2,vi;
signed main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}
int ch(int a,int b,int t)
{
	if(t==1)
	{
		if(a==4)
		{
			if(b==1)return 3;
			if(b==2)return 1;
			if(b==3)return 2;
		}
		if(a==3)
		{
			if(b==1)return 2;
			if(b==2)return 4;
			if(b==4)return 1;
		}
		if(a==2)
		{
			if(b==1)return 4;
			if(b==3)return 1;
			if(b==4)return 3;
		}
		if(a==1)
		{
			if(b==2)return 3;
			if(b==3)return 4;
			if(b==4)return 2;
		}
	}
	if(t==2)
	{
		if(a==4)
		{
			if(b==1)return 2;
			if(b==2)return 3;
			if(b==3)return 1;
		}
		if(a==3)
		{
			if(b==1)return 4;
			if(b==2)return 1;
			if(b==4)return 2;
		}
		if(a==2)
		{
			if(b==1)return 3;
			if(b==3)return 4;
			if(b==4)return 1;
		}
		if(a==1)
		{
			if(b==2)return 4;
			if(b==3)return 2;
			if(b==4)return 3;
		}
	}
}
queue<A>q;
void bfs()
{
	while(q.size())q.pop();
	q.push({1,1,4,1});
	d[1][1][1]=1;
	while(q.size())
	{
		A x=q.front();
		
		q.pop();
		if(x.j%2&&x.i<n)
		{
			if(!d[x.i+1][x.j+1][x.b]&&ch(x.a,x.b,2)==a[x.i+1][x.j+1])
			{
				d[x.i+1][x.j+1][x.b]=d[x.i][x.j][x.b]+1;
				if((x.i+1)==s1&&(x.j+1)==s2)
				{
					cout<<d[x.i+1][x.j+1][x.b]-1;
					vi=1;
					return;
				}
				q.push({x.i+1,x.j+1,a[x.i+1][x.j+1],x.b});
			}
		}
		if(x.j%2==0&&x.i>1)
		{
			int v=ch(x.a,x.b,1);
			if(!d[x.i-1][x.j-1][x.b]&&v==a[x.i-1][x.j-1])
			{
				d[x.i-1][x.j-1][x.b]=d[x.i][x.j][x.b]+1;
				if((x.i-1)==s1&&(x.j-1)==s2)
				{
					cout<<d[x.i-1][x.j-1][x.b]-1;
					vi=1;
					return;
				}
				q.push({x.i-1,x.j-1,a[x.i-1][x.j-1],x.b});
			}
		}
		if(x.j>1)
		{
			int v;
			if(x.j%2)v=ch(x.a,x.b,2);
		    else v=ch(x.a,x.b,1);
			if(!d[x.i][x.j-1][v]&&a[x.i][x.j-1]==x.b)
			{
				d[x.i][x.j-1][v]=d[x.i][x.j][x.b]+1;
				if((x.i)==s1&&(x.j-1)==s2)
				{
					cout<<d[x.i][x.j-1][v]-1;
					vi=1;
					return;
				}
				q.push({x.i,x.j-1,a[x.i][x.j-1],v});
			}
		}
		if(x.j<x.i*2-1)
		{
			int v;
			if(x.j%2)v=ch(x.a,x.b,1);
			else v=ch(x.a,x.b,2);
			if(!d[x.i][x.j+1][x.a]&&a[x.i][x.j+1]==v)
			{
				d[x.i][x.j+1][x.a]=d[x.i][x.j][x.b]+1;
				if((x.i)==s1&&(x.j+1)==s2)
				{
					cout<<d[x.i][x.j+1][x.a]-1;
					vi=1;
					return;
				}
				q.push({x.i,x.j+1,a[x.i][x.j+1],x.a});
			}
		}
	}
	
}
void solve()
{
	vi=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=2*i-1;j++)
		{
			cin>>a[i][j];
		}
	}
	cin>>s1>>s2;
	if(s1==1&&s2==1)
	{
		cout<<0;
		return;
	}
	bfs();
	if(!vi)cout<<-1;
	return;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3552kb

input:

3
4
3 2 3
4 3 2 1 3
3 1

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3480kb

input:

3
4
3 3 3
4 3 2 1 3
3 1

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3516kb

input:

2
4
1 3 3
2 3

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

2
4
1 2 3
2 2

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3972kb

input:

100
4
1 2 3
4 3 1 1 4
1 3 3 4 1 2 3
2 2 2 1 2 2 2 4 4
4 1 2 4 2 1 4 2 1 2 2
4 3 3 1 2 4 2 1 4 4 2 3 4
3 2 3 1 1 4 2 4 3 2 3 4 1 4 3
4 4 2 1 3 3 2 1 4 3 3 3 4 3 2 1 2
1 2 4 3 1 1 4 4 1 2 3 3 4 1 3 4 2 2 2
1 3 2 2 4 3 4 1 4 3 2 2 4 3 2 1 4 4 2 1 3
3 2 2 4 4 4 1 4 1 2 3 1 3 2 3 4 1 2 3 4 1 1 3
2 2 4 2 ...

output:

-1

result:

ok 1 number(s): "-1"

Test #6:

score: 0
Accepted
time: 1ms
memory: 3736kb

input:

100
4
1 3 3
2 3 2 1 4
1 1 1 4 1 4 3
4 2 2 1 4 3 2 1 4
4 3 3 4 1 2 2 4 3 4 2
4 3 2 1 1 2 2 1 4 4 2 1 2
1 2 3 4 1 2 1 4 4 4 3 4 1 4 3
1 3 4 2 3 4 3 1 4 2 2 1 4 1 1 3 4
2 2 3 4 3 2 2 4 4 1 3 4 2 2 3 4 3 1 3
3 3 3 2 4 3 2 2 4 3 1 1 4 3 1 1 4 1 2 2 3
1 2 2 4 3 2 3 3 2 4 3 4 1 2 2 4 3 1 4 4 1 2 3
4 4 4 2 ...

output:

-1

result:

ok 1 number(s): "-1"

Test #7:

score: 0
Accepted
time: 1ms
memory: 3680kb

input:

100
4
1 2 3
4 3 2 1 4
1 2 2 3 1 1 4
2 3 4 2 4 3 2 3 4
4 2 3 4 1 2 3 1 1 2 3
1 3 1 3 4 4 2 1 2 1 2 3 4
2 1 1 4 1 1 3 4 2 3 3 4 1 2 3
1 1 2 1 1 3 2 1 1 3 2 1 1 3 2 3 4
2 2 1 4 1 2 2 4 1 4 2 2 1 1 3 3 1 4 3
4 2 2 4 4 3 2 1 4 3 2 2 1 4 2 1 4 3 4 2 4
1 2 3 3 1 2 3 2 1 2 3 4 2 1 3 4 4 3 3 2 1 2 3
2 3 2 1 ...

output:

-1

result:

ok 1 number(s): "-1"

Test #8:

score: 0
Accepted
time: 1ms
memory: 3920kb

input:

100
4
1 1 4
4 3 2 1 4
3 2 1 4 1 4 3
1 3 3 1 2 2 3 3 3
1 2 3 1 1 2 3 2 1 1 1
1 3 2 1 4 3 2 1 4 3 2 1 1
2 2 3 3 3 2 3 4 4 3 3 4 1 3 4
4 3 2 3 4 1 2 1 4 3 1 1 2 2 1 1 1
1 2 3 2 1 1 2 4 3 2 3 4 1 2 3 4 1 3 3
4 4 3 2 4 3 2 3 3 3 3 2 4 3 2 1 3 3 2 1 4
2 2 3 4 1 2 3 4 3 2 3 4 3 2 3 4 4 2 1 4 1 2 3
4 3 4 4 ...

output:

-1

result:

ok 1 number(s): "-1"

Test #9:

score: 0
Accepted
time: 1ms
memory: 3884kb

input:

100
4
1 4 3
4 3 3 1 4
1 2 3 4 1 2 3
1 3 1 1 4 3 2 1 4
1 2 3 2 2 1 1 4 3 2 4
4 3 1 3 4 3 3 2 2 3 1 3 2
3 2 4 4 1 2 3 3 1 4 3 4 1 3 1
4 4 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4
1 2 3 4 3 1 3 4 1 2 1 4 1 2 3 4 1 1 3
2 3 2 1 2 3 2 1 4 4 2 1 2 3 2 1 4 3 1 1 4
1 2 4 4 1 3 3 4 1 2 2 4 1 2 3 4 4 4 3 2 1 2 1
4 3 2 1 ...

output:

-1

result:

ok 1 number(s): "-1"

Test #10:

score: 0
Accepted
time: 0ms
memory: 3952kb

input:

100
4
4 1 3
4 3 2 1 1
4 2 2 4 1 2 4
2 3 1 2 1 3 2 1 4
1 3 3 4 1 2 1 4 1 4 3
3 3 2 1 1 3 2 2 4 3 2 1 4
1 2 3 1 1 2 3 4 1 3 3 3 1 2 1
4 1 2 1 4 3 2 1 4 2 2 1 4 3 2 1 4
2 4 3 2 1 2 3 2 1 3 3 4 2 2 3 4 1 2 3
4 3 2 1 4 2 2 2 4 3 2 1 4 2 2 1 3 3 4 4 4
1 2 3 1 3 2 3 4 2 2 3 4 1 2 3 4 1 2 2 4 1 3 1
4 3 2 2 ...

output:

-1

result:

ok 1 number(s): "-1"

Test #11:

score: 0
Accepted
time: 1ms
memory: 3736kb

input:

100
4
1 2 3
1 3 2 1 2
1 2 2 4 4 4 3
2 3 2 3 4 3 2 1 4
1 2 4 4 1 2 1 4 1 4 3
2 3 1 1 2 3 2 1 4 3 2 1 4
1 2 3 4 1 2 3 4 1 4 3 4 3 2 3
4 3 2 1 4 3 2 2 4 3 2 1 4 3 2 1 4
1 2 3 4 1 1 3 4 4 3 3 4 1 2 3 4 1 2 3
4 3 2 1 4 3 4 1 1 3 3 2 4 4 2 1 4 3 2 3 3
1 2 3 4 1 2 4 4 1 2 1 4 1 2 3 3 4 3 2 4 1 3 3
2 3 2 1 ...

output:

-1

result:

ok 1 number(s): "-1"

Test #12:

score: 0
Accepted
time: 0ms
memory: 3696kb

input:

100
4
4 2 3
4 3 2 1 3
1 3 2 4 1 2 3
4 3 2 1 3 3 4 1 3
1 2 3 1 1 1 3 1 1 2 3
4 3 2 1 4 3 2 1 4 3 2 4 1
1 2 3 4 1 2 4 4 1 3 2 4 1 4 1
3 1 2 2 4 3 4 1 1 1 2 3 4 3 2 1 4
3 2 4 2 2 2 2 1 3 2 3 1 1 1 3 4 1 2 3
4 3 2 2 4 2 2 3 4 2 2 1 4 3 2 1 4 3 2 4 3
1 2 4 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 2
4 3 2 1 ...

output:

-1

result:

ok 1 number(s): "-1"

Test #13:

score: 0
Accepted
time: 0ms
memory: 4340kb

input:

100
4
1 2 3
4 3 2 4 4
1 2 3 4 4 2 3
4 3 2 4 4 3 3 1 4
3 1 3 4 1 2 3 4 1 2 1
4 3 2 1 4 3 2 1 4 4 3 1 4
1 2 3 4 1 2 3 4 1 2 3 1 1 4 3
4 1 2 3 4 3 2 1 4 3 2 1 4 4 3 1 3
1 2 1 4 2 2 4 4 1 2 3 4 1 2 3 3 2 2 3
4 1 3 1 4 3 2 2 4 1 2 1 3 3 2 1 4 1 2 3 4
1 2 3 4 3 3 1 4 1 2 3 1 1 2 3 4 1 2 3 3 1 2 3
4 3 2 1 ...

output:

-1

result:

ok 1 number(s): "-1"

Test #14:

score: 0
Accepted
time: 1ms
memory: 3688kb

input:

100
4
1 2 1
2 2 2 1 4
2 2 3 4 1 2 3
4 4 2 2 4 3 2 1 4
1 2 3 3 1 2 1 4 1 2 1
4 3 2 3 4 3 2 1 4 3 2 1 4
1 2 1 4 1 2 3 4 1 2 3 4 1 2 3
2 1 2 1 4 3 2 1 3 4 2 1 4 3 2 1 4
2 3 3 3 1 2 2 4 1 2 3 4 1 3 4 4 2 2 3
4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4
1 2 4 3 1 2 3 4 1 4 3 4 4 2 3 2 1 2 3 4 1 3 2
4 3 2 1 ...

output:

-1

result:

ok 1 number(s): "-1"

Test #15:

score: 0
Accepted
time: 1ms
memory: 3956kb

input:

100
4
1 2 3
4 3 2 2 4
1 2 2 4 1 2 3
4 3 4 1 4 2 2 1 4
1 2 1 4 1 2 3 4 3 2 3
4 3 2 1 4 3 2 1 4 4 3 2 4
2 2 3 4 1 2 2 4 3 2 3 3 1 1 2
4 3 2 1 4 3 2 1 4 2 2 1 4 1 2 1 1
1 1 3 4 1 3 1 4 2 2 3 4 3 2 3 4 1 2 3
4 3 2 1 4 1 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4
3 2 3 4 1 2 3 4 1 3 3 3 1 4 3 1 1 2 3 4 1 2 3
4 4 2 1 ...

output:

86

result:

ok 1 number(s): "86"

Test #16:

score: 0
Accepted
time: 2ms
memory: 4292kb

input:

100
4
1 2 3
1 3 2 1 4
1 2 3 4 2 2 3
4 1 2 1 3 3 2 3 4
3 2 3 4 1 2 3 4 1 2 3
4 3 2 1 4 3 2 2 4 1 2 1 4
1 2 3 4 1 2 1 4 1 2 3 4 2 2 3
4 2 2 1 4 3 2 2 4 3 2 1 3 3 2 1 4
1 2 3 3 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3
4 3 2 1 4 3 2 1 4 3 2 1 4 4 2 1 4 3 2 1 4
1 2 3 4 4 2 3 4 1 2 3 4 1 2 3 2 1 2 4 1 1 2 3
4 3 3 1 ...

output:

207

result:

ok 1 number(s): "207"

Test #17:

score: 0
Accepted
time: 0ms
memory: 4344kb

input:

100
4
1 2 3
4 3 2 1 4
1 2 3 4 1 2 3
4 3 4 1 4 1 2 1 4
1 2 3 4 1 2 3 3 1 2 3
4 3 2 1 2 3 2 3 4 3 2 1 4
1 2 3 4 4 2 4 4 1 2 3 1 1 2 3
4 3 2 1 4 1 2 1 4 3 2 1 4 3 2 1 1
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3
4 3 3 1 4 3 2 1 4 3 2 1 1 3 2 1 4 3 2 1 4
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 3 3
4 3 1 1 ...

output:

-1

result:

ok 1 number(s): "-1"

Test #18:

score: 0
Accepted
time: 2ms
memory: 4108kb

input:

100
4
1 2 3
4 3 2 2 2
1 4 3 4 1 2 3
4 3 2 1 4 3 2 1 3
1 2 3 4 1 2 3 4 1 2 3
4 3 2 1 4 3 2 1 4 3 2 1 2
1 2 4 1 1 2 3 4 1 2 3 4 1 2 3
4 3 2 1 3 3 4 1 3 3 2 1 4 3 1 1 4
1 2 3 4 1 2 1 4 2 2 3 3 1 2 3 4 1 2 3
1 1 2 1 4 3 2 1 4 2 1 1 4 3 2 1 4 3 2 1 4
1 2 1 4 2 4 3 4 1 2 3 4 1 4 3 4 1 2 3 4 1 1 3
4 3 2 1 ...

output:

143

result:

ok 1 number(s): "143"

Test #19:

score: 0
Accepted
time: 2ms
memory: 4220kb

input:

100
4
1 2 3
4 3 2 1 4
1 2 1 4 1 2 3
4 3 2 1 4 3 2 1 4
1 2 3 4 1 2 3 4 3 2 3
4 3 1 3 4 3 2 1 4 3 2 1 4
1 2 3 4 1 2 3 4 1 2 1 4 1 2 3
1 3 2 1 4 3 2 1 4 3 1 4 4 3 2 1 4
1 2 3 4 1 4 3 4 1 2 3 4 1 2 3 4 4 2 4
3 3 2 1 4 3 2 4 4 3 2 1 4 4 1 1 4 3 2 1 4
1 2 3 4 1 1 3 4 1 2 3 1 1 2 2 4 1 2 3 4 1 2 3
4 3 2 1 ...

output:

179

result:

ok 1 number(s): "179"

Test #20:

score: 0
Accepted
time: 0ms
memory: 3744kb

input:

100
4
1 2 3
4 3 2 1 4
1 2 3 2 1 2 2
4 3 2 1 2 1 2 1 4
1 2 3 4 1 2 3 4 1 3 3
4 3 2 1 4 3 2 4 4 3 2 1 4
2 2 3 4 1 2 3 4 1 3 3 4 1 2 3
4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4
1 2 3 4 4 2 3 4 1 2 3 4 1 2 2 4 1 2 3
4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4
1 2 2 4 1 2 3 4 3 2 3 4 1 2 3 4 1 2 3 4 2 4 3
4 3 2 1 ...

output:

2

result:

ok 1 number(s): "2"

Test #21:

score: 0
Accepted
time: 2ms
memory: 4556kb

input:

100
4
1 2 3
4 3 2 1 4
1 2 3 4 1 2 3
4 3 2 4 4 3 2 1 4
1 2 3 4 1 2 3 4 1 2 3
4 3 2 1 4 3 2 1 4 3 2 1 4
1 2 3 4 1 2 3 4 1 2 3 4 1 1 3
4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3
4 3 2 1 4 3 2 1 2 3 2 1 4 3 2 1 4 3 2 1 4
1 2 3 4 1 2 3 4 1 4 3 4 1 2 3 4 1 2 3 4 1 2 3
4 3 2 1 ...

output:

-1

result:

ok 1 number(s): "-1"

Test #22:

score: 0
Accepted
time: 2ms
memory: 4328kb

input:

100
4
1 2 3
4 3 2 1 4
1 2 3 4 1 2 3
4 3 2 1 4 3 2 1 4
1 3 3 4 1 2 3 4 1 2 3
4 3 2 2 4 3 2 1 4 3 2 1 4
1 2 3 4 1 2 3 4 3 2 3 4 2 2 3
4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 3
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3
4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4
1 4 3 4 1 2 3 3 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3
4 3 2 1 ...

output:

160

result:

ok 1 number(s): "160"

Test #23:

score: 0
Accepted
time: 1ms
memory: 4020kb

input:

100
4
1 2 3
4 3 1 1 4
1 2 3 4 1 3 3
4 3 2 1 4 3 2 1 4
1 2 3 4 1 2 3 4 1 2 3
4 3 2 1 4 3 2 1 4 3 2 1 4
1 2 3 4 1 2 3 4 1 2 3 4 1 2 4
4 3 2 1 4 3 2 1 4 3 2 1 2 3 2 1 4
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 3 3
4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4
1 2 3 4 1 2 3 4 1 1 3 4 1 2 3 4 1 2 3 4 1 4 3
4 3 2 1 ...

output:

24

result:

ok 1 number(s): "24"

Test #24:

score: 0
Accepted
time: 2ms
memory: 4108kb

input:

100
4
1 2 3
4 3 2 1 4
1 2 3 4 1 2 3
4 3 2 1 4 3 2 1 4
1 2 3 4 1 2 3 4 1 2 3
4 3 2 1 4 3 2 1 4 3 2 1 4
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3
4 3 2 4 4 3 2 1 4 3 2 1 4 3 2 1 4
1 2 3 4 1 2 3 4 1 2 3 3 1 2 3 4 1 2 3
4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 4 4 3 2 1 4
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3
4 3 2 1 ...

output:

131

result:

ok 1 number(s): "131"

Test #25:

score: 0
Accepted
time: 2ms
memory: 4272kb

input:

100
4
1 2 3
4 3 2 4 4
1 2 2 4 1 2 3
4 4 2 1 4 2 2 1 4
1 2 3 4 4 2 3 4 4 2 3
4 3 2 2 4 3 2 2 4 3 2 3 4
1 2 2 4 1 2 1 4 1 2 4 4 1 2 3
4 2 2 1 4 4 2 1 4 4 2 1 4 1 2 1 4
1 2 3 4 3 2 3 4 3 2 3 4 3 2 3 4 2 2 3
4 3 2 4 4 3 2 4 4 3 2 2 4 3 2 3 4 3 2 2 4
1 2 2 4 1 2 4 4 1 2 4 4 1 2 4 4 1 2 4 4 1 2 3
4 2 2 1 ...

output:

7352

result:

ok 1 number(s): "7352"

Test #26:

score: 0
Accepted
time: 0ms
memory: 4224kb

input:

100
4
1 2 2
4 3 2 1 4
4 1 4 1 3 2 3
4 3 2 1 4 3 2 1 4
1 2 2 1 4 4 1 2 3 3 2
4 3 2 1 4 3 2 1 4 3 2 1 4
3 3 1 3 3 3 1 3 2 1 2 1 3 2 3
4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4
1 2 1 1 4 1 1 3 3 4 1 2 3 1 2 3 3 1 2
4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4
2 4 2 3 3 3 1 2 2 3 1 3 4 1 1 3 3 1 1 1 4 2 3
4 3 2 1 ...

output:

4996

result:

ok 1 number(s): "4996"

Test #27:

score: 0
Accepted
time: 0ms
memory: 4552kb

input:

100
4
1 2 3
4 3 2 4 4
1 2 1 4 1 2 3
4 4 2 1 4 1 2 1 4
1 2 3 4 4 2 3 4 3 2 3
4 3 2 4 4 3 2 2 4 3 2 3 4
1 2 2 4 1 2 1 4 1 2 2 4 1 2 3
4 4 2 1 4 4 2 1 4 1 2 1 4 2 2 1 4
1 2 3 4 3 2 3 4 4 2 3 4 4 2 3 4 2 2 3
4 3 2 4 4 3 2 2 4 3 2 2 4 3 2 2 4 3 2 3 4
1 2 4 4 1 2 1 4 1 2 2 4 1 2 2 4 1 2 2 4 1 2 3
4 2 2 1 ...

output:

3736

result:

ok 1 number(s): "3736"

Test #28:

score: 0
Accepted
time: 0ms
memory: 4192kb

input:

100
4
1 2 1
4 3 2 1 4
2 1 4 1 3 2 3
4 3 2 1 4 3 2 1 4
1 2 1 2 2 4 2 1 4 1 4
4 3 2 1 4 3 2 1 4 3 2 1 4
2 1 1 2 4 1 1 1 4 4 1 3 3 2 3
4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4
1 2 4 3 3 4 2 2 2 4 4 1 4 3 1 3 3 1 2
4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4
4 1 3 1 4 4 1 1 2 4 1 2 3 4 4 2 3 1 1 2 2 2 3
4 3 2 1 ...

output:

4716

result:

ok 1 number(s): "4716"

Test #29:

score: 0
Accepted
time: 2ms
memory: 4320kb

input:

100
4
1 2 3
4 3 2 4 4
1 2 1 4 1 2 3
4 1 2 1 4 2 2 1 4
1 2 3 4 4 2 3 4 4 2 3
4 3 2 2 4 3 2 4 4 3 2 4 4
1 2 2 4 1 2 1 4 1 2 1 4 1 2 3
4 2 2 1 4 4 2 1 4 1 2 1 4 1 2 1 4
1 2 3 4 4 2 3 4 4 2 3 4 4 2 3 4 4 2 3
4 3 2 3 4 3 2 3 4 3 2 4 4 3 2 4 4 3 2 3 4
1 2 1 4 1 2 2 4 1 2 4 4 1 2 4 4 1 2 1 4 1 2 3
4 2 2 1 ...

output:

2255

result:

ok 1 number(s): "2255"

Test #30:

score: 0
Accepted
time: 0ms
memory: 4268kb

input:

100
4
1 2 2
4 3 2 1 4
3 1 4 1 4 2 3
4 3 2 1 4 3 2 1 4
1 2 1 3 2 4 2 3 4 3 1
4 3 2 1 4 3 2 1 4 3 2 1 4
1 1 2 3 2 4 2 1 4 2 1 3 1 2 3
4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4
1 2 1 1 3 3 1 2 4 1 4 2 4 4 2 2 2 3 3
4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4
3 4 1 4 4 3 1 3 2 1 4 1 2 3 4 1 4 4 4 1 1 2 3
4 3 2 1 ...

output:

3598

result:

ok 1 number(s): "3598"

Test #31:

score: 0
Accepted
time: 2ms
memory: 4332kb

input:

100
4
1 2 3
4 3 2 4 4
1 2 2 4 1 2 3
4 2 2 1 4 4 2 1 4
1 2 3 4 2 2 3 4 3 2 3
4 3 2 3 4 3 2 4 4 3 2 3 4
1 2 4 4 1 2 2 4 1 2 2 4 1 2 3
4 4 2 1 4 4 2 1 4 1 2 1 4 1 2 1 4
1 2 3 4 3 2 3 4 3 2 3 4 3 2 3 4 3 2 3
4 3 2 4 4 3 2 3 4 3 2 2 4 3 2 4 4 3 2 4 4
1 2 2 4 1 2 1 4 1 2 3 4 1 2 4 4 1 2 1 4 1 2 3
4 1 2 1 ...

output:

2458

result:

ok 1 number(s): "2458"

Test #32:

score: 0
Accepted
time: 2ms
memory: 4196kb

input:

100
4
1 2 1
4 3 2 1 4
4 1 2 1 2 2 3
4 3 2 1 4 3 2 1 4
1 2 4 2 4 1 3 3 2 1 4
4 3 2 1 4 3 2 1 4 3 2 1 4
4 1 1 2 2 4 2 1 2 4 4 1 2 2 3
4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4
1 2 2 2 2 3 1 4 2 4 4 4 4 2 1 2 4 2 3
4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4
2 4 2 2 4 3 1 1 3 2 4 1 2 4 4 1 3 3 4 1 3 2 3
4 3 2 1 ...

output:

2009

result:

ok 1 number(s): "2009"

Test #33:

score: 0
Accepted
time: 2ms
memory: 4304kb

input:

100
4
1 2 3
4 3 2 2 4
1 2 4 4 1 2 3
4 2 2 1 4 1 2 1 4
1 2 3 4 4 2 3 4 2 2 3
4 3 2 2 4 3 2 4 4 3 2 4 4
1 2 4 4 1 2 4 4 1 2 2 4 1 2 3
4 1 2 1 4 2 2 1 4 2 2 1 4 4 2 1 4
1 2 3 4 3 2 3 4 4 2 3 4 3 2 3 4 2 2 3
4 3 2 4 4 3 2 2 4 3 2 4 4 3 2 4 4 3 2 2 4
1 2 1 4 1 2 1 4 1 2 2 4 1 2 4 4 1 2 4 4 1 2 3
4 2 2 1 ...

output:

1638

result:

ok 1 number(s): "1638"

Test #34:

score: 0
Accepted
time: 2ms
memory: 4328kb

input:

100
4
1 2 2
4 3 2 1 4
1 1 4 3 2 2 3
4 3 2 1 4 3 2 1 4
1 2 3 3 3 1 2 1 3 1 3
4 3 2 1 4 3 2 1 4 3 2 1 4
4 4 2 3 4 2 2 4 2 1 4 2 3 2 3
4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4
1 2 3 4 3 3 4 3 4 2 3 3 2 1 4 2 2 2 3
4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4
2 3 3 2 3 3 2 4 3 2 3 1 2 2 2 3 1 2 4 4 4 2 3
4 3 2 1 ...

output:

1723

result:

ok 1 number(s): "1723"

Test #35:

score: 0
Accepted
time: 0ms
memory: 4556kb

input:

100
4
1 2 3
3 3 2 4 4
1 2 3 4 4 2 3
1 3 2 4 4 3 2 1 4
1 2 3 4 2 2 3 2 1 2 3
3 3 2 2 4 3 2 1 2 3 2 4 4
1 2 3 4 2 2 3 2 1 2 3 4 4 2 3
3 3 2 4 4 3 2 1 1 3 2 2 4 3 2 1 4
1 2 3 4 4 2 3 3 1 2 3 4 2 2 3 2 1 2 3
1 3 2 4 4 3 2 1 3 3 2 2 4 3 2 1 2 3 2 2 4
1 2 3 4 2 2 3 2 1 2 3 4 4 2 3 1 1 2 3 4 3 2 3
1 3 2 3 ...

output:

7352

result:

ok 1 number(s): "7352"

Test #36:

score: 0
Accepted
time: 2ms
memory: 4548kb

input:

100
4
2 2 3
1 2 2 1 3
4 4 3 4 2 3 3
3 2 2 1 3 2 2 1 4
4 3 3 4 4 4 3 4 4 2 3
1 4 2 1 3 2 2 1 2 4 2 1 3
3 4 3 4 2 3 3 4 2 3 3 4 4 4 3
2 4 2 1 3 1 2 1 3 1 2 1 1 1 2 1 4
4 4 3 4 2 3 3 4 4 3 3 4 4 4 3 4 4 2 3
1 4 2 1 1 4 2 1 3 4 2 1 2 1 2 1 2 4 2 1 2
4 1 3 4 3 4 3 4 2 1 3 4 4 4 3 4 4 1 3 4 4 1 3
1 4 2 1 ...

output:

4998

result:

ok 1 number(s): "4998"

Test #37:

score: 0
Accepted
time: 2ms
memory: 4288kb

input:

100
4
1 2 3
1 3 2 4 4
1 2 3 4 4 2 3
2 3 2 4 4 3 2 1 4
1 2 3 4 3 2 3 4 1 2 3
1 3 2 2 4 3 2 1 1 3 2 4 4
1 2 3 4 2 2 3 2 1 2 3 4 3 2 3
3 3 2 2 4 3 2 1 2 3 2 4 4 3 2 1 4
1 2 3 4 4 2 3 1 1 2 3 4 2 2 3 3 1 2 3
2 3 2 2 4 3 2 1 2 3 2 2 4 3 2 1 1 3 2 2 4
1 2 3 4 2 2 3 3 1 2 3 4 4 2 3 2 1 2 3 4 3 2 3
1 3 2 3 ...

output:

3288

result:

ok 1 number(s): "3288"

Test #38:

score: 0
Accepted
time: 2ms
memory: 4208kb

input:

100
4
1 2 3
1 2 2 1 2
3 4 3 4 4 1 3
2 3 2 1 2 4 2 1 4
3 1 3 4 4 3 3 4 4 2 3
3 2 2 1 3 2 2 1 2 4 2 1 3
3 1 3 4 4 3 3 4 4 1 3 4 2 4 3
2 1 2 1 2 2 2 1 2 2 2 1 3 2 2 1 4
2 1 3 4 3 3 3 4 3 1 3 4 4 4 3 4 3 2 3
2 1 2 1 2 1 2 1 2 4 2 1 3 4 2 1 1 4 2 1 1
2 1 3 4 1 4 3 4 3 4 3 4 3 4 3 4 2 4 3 4 3 3 3
2 2 2 1 ...

output:

4607

result:

ok 1 number(s): "4607"

Test #39:

score: 0
Accepted
time: 2ms
memory: 4344kb

input:

100
4
1 2 3
1 3 2 2 4
1 2 3 4 2 2 3
3 3 2 2 4 3 2 1 4
1 2 3 4 3 2 3 2 1 2 3
1 3 2 3 4 3 2 1 1 3 2 3 4
1 2 3 4 2 2 3 1 1 2 3 4 3 2 3
1 3 2 2 4 3 2 1 2 3 2 2 4 3 2 1 4
1 2 3 4 2 2 3 1 1 2 3 4 4 2 3 2 1 2 3
1 3 2 3 4 3 2 1 4 3 2 3 4 3 2 1 2 3 2 3 4
1 2 3 4 3 2 3 1 1 2 3 4 3 2 3 2 1 2 3 4 2 2 3
2 3 2 3 ...

output:

2271

result:

ok 1 number(s): "2271"

Test #40:

score: 0
Accepted
time: 2ms
memory: 4284kb

input:

100
4
4 2 3
2 2 2 1 3
2 4 3 4 2 4 3
1 2 2 1 3 2 2 1 4
2 1 3 4 3 4 3 4 2 2 3
2 4 2 1 3 1 2 1 1 2 2 1 1
2 1 3 4 1 3 3 4 4 4 3 4 2 3 3
3 4 2 1 3 4 2 1 1 1 2 1 2 1 2 1 4
4 3 3 4 4 1 3 4 3 1 3 4 3 4 3 4 2 2 3
3 4 2 1 1 1 2 1 2 4 2 1 3 4 2 1 2 1 2 1 2
3 1 3 4 2 4 3 4 4 3 3 4 4 4 3 4 2 1 3 4 4 4 3
2 2 2 1 ...

output:

2950

result:

ok 1 number(s): "2950"

Test #41:

score: 0
Accepted
time: 2ms
memory: 4280kb

input:

100
4
1 2 3
1 3 2 4 4
1 2 3 4 3 2 3
1 3 2 2 4 3 2 1 4
1 2 3 4 4 2 3 1 1 2 3
2 3 2 3 4 3 2 1 3 3 2 2 4
1 2 3 4 3 2 3 3 1 2 3 4 3 2 3
3 3 2 3 4 3 2 1 3 3 2 2 4 3 2 1 4
1 2 3 4 4 2 3 1 1 2 3 4 3 2 3 2 1 2 3
1 3 2 2 4 3 2 1 3 3 2 4 4 3 2 1 1 3 2 4 4
1 2 3 4 2 2 3 3 1 2 3 4 4 2 3 1 1 2 3 4 2 2 3
1 3 2 3 ...

output:

1618

result:

ok 1 number(s): "1618"

Test #42:

score: 0
Accepted
time: 2ms
memory: 4212kb

input:

100
4
2 2 3
2 2 2 1 1
2 1 3 4 2 4 3
4 1 2 1 2 3 2 1 4
2 3 3 4 4 3 3 4 3 2 3
2 1 2 1 2 1 2 1 3 4 2 1 3
1 1 3 4 4 3 3 4 2 3 3 4 4 3 3
3 1 2 1 2 3 2 1 4 4 2 1 3 1 2 1 4
4 3 3 4 3 4 3 4 2 4 3 4 3 4 3 4 4 2 3
1 1 2 1 3 1 2 1 1 2 2 1 4 2 2 1 1 4 2 1 4
2 4 3 4 4 4 3 4 3 4 3 4 2 4 3 4 4 3 3 4 1 1 3
4 4 2 1 ...

output:

2054

result:

ok 1 number(s): "2054"

Test #43:

score: 0
Accepted
time: 2ms
memory: 4272kb

input:

100
4
1 2 3
3 3 2 4 4
1 2 3 4 2 2 3
4 3 2 2 4 3 2 1 4
1 2 3 4 2 2 3 1 1 2 3
4 3 2 4 4 3 2 1 2 3 2 3 4
1 2 3 4 2 2 3 3 1 2 3 4 4 2 3
3 3 2 2 4 3 2 1 1 3 2 3 4 3 2 1 4
1 2 3 4 3 2 3 1 1 2 3 4 3 2 3 3 1 2 3
1 3 2 4 4 3 2 1 3 3 2 4 4 3 2 1 2 3 2 4 4
1 2 3 4 3 2 3 2 1 2 3 4 3 2 3 1 1 2 3 4 2 2 3
1 3 2 2 ...

output:

1217

result:

ok 1 number(s): "1217"

Test #44:

score: 0
Accepted
time: 2ms
memory: 4516kb

input:

100
4
2 2 3
1 1 2 1 1
1 3 3 4 2 1 3
3 2 2 1 1 4 2 1 4
1 1 3 4 4 3 3 4 3 2 3
1 4 2 1 2 2 2 1 3 1 2 1 1
2 1 3 4 2 3 3 4 4 3 3 4 3 1 3
1 1 2 1 3 4 2 1 2 2 2 1 3 4 2 1 4
3 3 3 4 1 1 3 4 4 4 3 4 4 1 3 4 3 2 3
3 1 2 1 3 4 2 1 3 2 2 1 2 3 2 1 4 1 2 1 2
2 3 3 4 4 4 3 4 4 3 3 4 4 1 3 4 3 3 3 4 4 1 3
4 2 2 1 ...

output:

1546

result:

ok 1 number(s): "1546"

Test #45:

score: 0
Accepted
time: 0ms
memory: 3872kb

input:

100
4
3 2 3
4 3 2 1 3
1 2 1 1 1 2 3
2 3 2 1 4 1 2 1 2
1 2 3 3 1 2 2 4 1 2 3
4 4 2 1 4 3 1 2 3 4 2 1 4
1 2 4 4 1 1 3 4 1 4 3 4 1 3 3
4 3 2 3 4 3 4 1 3 3 2 1 2 3 2 1 2
1 2 3 3 1 2 2 3 3 1 2 4 2 2 3 4 1 2 3
4 3 3 1 2 3 2 1 4 4 2 1 4 3 2 2 4 3 1 1 4
1 2 3 1 1 2 3 1 2 2 3 4 4 4 3 4 1 1 3 4 2 2 3
4 3 4 4 ...

output:

320

result:

ok 1 number(s): "320"

Test #46:

score: 0
Accepted
time: 2ms
memory: 4192kb

input:

100
4
4 2 3
4 3 3 1 4
1 2 3 3 1 2 4
4 3 2 3 4 3 1 1 4
2 2 3 3 1 2 4 4 1 2 3
4 3 2 1 2 3 2 1 4 4 2 1 4
1 2 1 4 1 2 3 1 1 2 2 4 4 2 3
4 3 2 4 4 3 1 4 4 3 3 1 4 3 2 1 4
1 2 4 4 1 4 3 4 1 2 4 4 1 2 3 1 1 2 3
4 3 4 4 1 3 2 1 2 4 2 1 4 4 3 1 4 1 2 1 4
1 2 2 4 1 2 3 2 1 2 3 4 4 2 3 4 1 1 1 4 1 4 2
4 3 3 1 ...

output:

1027

result:

ok 1 number(s): "1027"

Test #47:

score: 0
Accepted
time: 2ms
memory: 4428kb

input:

100
4
1 2 1
2 3 2 1 4
1 2 3 1 1 2 2
4 3 1 1 4 3 3 1 4
4 2 3 4 1 1 3 4 1 2 3
4 3 2 3 4 3 4 1 4 2 2 1 4
1 2 3 3 1 2 1 4 1 2 3 2 3 2 3
4 1 2 1 3 3 2 1 4 1 4 1 4 3 2 2 4
1 2 3 4 1 2 3 1 4 2 3 4 1 1 3 4 1 2 3
4 3 3 1 4 2 4 1 4 3 2 3 3 3 2 3 4 2 2 1 4
1 2 3 4 4 2 3 4 1 3 3 4 1 2 2 4 1 2 3 4 2 2 3
4 4 2 1 ...

output:

1147

result:

ok 1 number(s): "1147"

Test #48:

score: 0
Accepted
time: 2ms
memory: 4272kb

input:

100
4
1 2 3
4 1 2 1 1
1 2 2 4 1 2 3
4 3 2 1 2 1 2 1 3
1 2 3 3 1 2 3 4 3 2 3
4 3 4 1 3 3 2 3 4 3 1 1 4
1 2 3 4 1 2 3 4 3 2 3 4 1 2 3
4 3 3 1 4 1 2 4 4 3 2 3 4 3 1 1 4
3 2 3 4 1 4 3 4 1 2 1 4 4 2 3 4 3 2 3
4 3 2 2 4 3 1 1 2 3 2 1 4 3 2 1 1 4 3 1 4
1 2 2 4 4 2 3 2 1 2 3 4 2 3 3 2 1 2 3 4 2 2 3
4 3 2 1 ...

output:

2292

result:

ok 1 number(s): "2292"

Test #49:

score: 0
Accepted
time: 1ms
memory: 4040kb

input:

100
4
1 2 4
3 3 2 1 4
1 2 3 2 1 2 3
4 3 1 1 2 3 1 1 4
1 2 3 4 1 2 3 4 2 2 3
4 3 3 1 4 1 2 1 4 3 3 1 4
1 4 3 4 1 3 3 4 4 2 2 4 1 2 3
4 3 2 1 1 3 2 1 4 4 2 1 4 3 1 1 4
3 2 3 3 1 2 3 4 1 3 3 4 4 4 3 4 1 3 3
4 3 2 1 1 3 2 3 4 1 2 1 3 3 2 1 1 3 2 1 3
1 2 3 3 1 2 3 4 3 2 3 4 1 4 3 4 1 2 2 2 1 2 3
4 3 4 1 ...

output:

67

result:

ok 1 number(s): "67"

Test #50:

score: 0
Accepted
time: 1ms
memory: 3964kb

input:

100
4
4 2 3
4 3 1 1 4
1 2 3 2 1 2 1
4 3 2 4 3 3 2 1 4
1 3 3 4 1 2 4 4 1 1 3
4 3 2 1 4 1 2 1 4 3 4 1 4
1 2 2 4 1 3 1 4 1 1 2 4 1 2 3
2 3 2 1 1 3 2 1 3 3 2 1 4 2 2 1 4
1 2 3 4 1 3 3 4 3 2 3 3 2 2 3 3 1 2 3
4 3 3 1 2 3 4 1 4 3 2 1 4 3 4 1 4 1 2 1 4
3 3 3 4 1 2 3 4 1 4 3 4 1 3 2 1 4 2 3 1 1 2 3
4 2 2 1 ...

output:

532

result:

ok 1 number(s): "532"

Test #51:

score: 0
Accepted
time: 1ms
memory: 3844kb

input:

100
4
2 2 3
4 3 2 1 3
3 2 3 3 1 2 3
4 3 4 1 4 2 2 1 4
1 2 3 4 1 2 1 4 4 2 3
4 3 2 3 4 1 2 1 4 3 2 1 4
4 2 3 3 1 2 3 3 1 2 3 1 1 2 4
4 3 1 1 4 3 1 1 4 3 3 1 2 3 2 1 4
1 2 3 4 1 1 4 4 1 3 3 4 1 2 3 1 1 2 3
4 3 3 1 2 3 2 1 4 3 2 4 4 3 3 1 2 3 2 3 4
1 2 4 4 1 3 3 4 2 2 2 4 1 2 3 3 1 2 2 4 1 2 3
1 3 2 3 ...

output:

275

result:

ok 1 number(s): "275"

Test #52:

score: 0
Accepted
time: 1ms
memory: 3780kb

input:

100
4
4 2 3
4 3 1 1 4
1 2 3 3 1 2 2
4 2 2 1 4 3 3 1 4
1 2 3 4 2 1 3 4 1 2 3
4 2 2 1 1 3 2 1 4 2 2 1 4
1 2 2 4 1 2 2 4 1 3 3 4 4 2 3
4 3 2 1 1 3 2 1 4 1 2 1 1 3 2 1 4
3 4 3 4 4 2 3 2 2 2 3 4 3 2 3 4 2 2 3
4 1 2 1 4 3 2 1 4 3 2 2 1 2 1 1 4 3 2 3 4
1 2 3 4 3 4 3 2 1 1 4 4 1 1 3 4 1 1 4 4 1 2 3
4 3 2 2 ...

output:

54

result:

ok 1 number(s): "54"

Test #53:

score: 0
Accepted
time: 2ms
memory: 4160kb

input:

100
4
1 2 1
4 3 1 1 4
1 2 2 3 3 2 3
3 3 2 1 4 3 2 1 4
1 2 3 1 1 4 1 2 1 2 4
4 3 2 4 4 3 2 2 4 3 3 1 4
1 2 1 4 1 2 4 4 1 2 2 3 3 2 3
4 3 3 4 2 1 2 1 4 2 2 1 4 3 2 1 4
4 2 3 4 1 4 3 4 4 2 3 4 3 2 1 4 1 4 3
4 3 2 4 3 3 2 2 4 3 2 1 2 4 3 1 4 3 2 1 4
1 2 4 4 1 2 4 4 1 3 4 4 1 2 3 4 1 4 3 4 2 2 3
2 3 2 3 ...

output:

1360

result:

ok 1 number(s): "1360"

Test #54:

score: 0
Accepted
time: 2ms
memory: 4524kb

input:

100
4
3 2 3
4 3 1 1 4
1 2 3 1 1 2 4
3 2 2 1 3 3 2 1 4
1 4 3 4 1 2 3 2 1 2 4
4 3 2 1 1 3 2 2 4 3 1 1 4
1 2 3 1 1 2 2 4 1 2 1 4 1 2 3
4 3 2 4 4 3 2 1 4 4 2 1 4 4 2 1 4
1 1 3 4 2 2 3 1 1 2 3 2 1 2 3 4 1 1 3
4 3 2 1 2 3 2 1 1 3 1 1 4 2 2 1 1 3 2 1 4
1 3 3 4 4 2 3 4 3 2 3 4 1 2 1 4 1 2 3 1 1 2 1
4 3 3 1 ...

output:

2448

result:

ok 1 number(s): "2448"

Test #55:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

3
4
3 2 3
3 3 2 1 3
3 1

output:

-1

result:

ok 1 number(s): "-1"

Extra Test:

score: 0
Extra Test Passed