QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#75006#5446. 琪露诺的符卡交换XZTmaxsmall6740 49ms7372kbC++141.3kb2023-02-04 14:15:012023-02-04 14:15:02

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-04 14:15:02]
  • 评测
  • 测评结果:40
  • 用时:49ms
  • 内存:7372kb
  • [2023-02-04 14:15:01]
  • 提交

answer

#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define mk make_pair
#define pb push_back
using namespace std;
const int N=510;
int n;
int vis[N],ch[N];
int a[N][N],ans[N][N];
multiset<int>e[N];
int dfs(int x)
{
	for(auto y:e[x])
	{
		if(vis[y])continue;vis[y]=1;
		if(!ch[y]||dfs(ch[y]))
		{
			ch[x]=y;ch[y]=x;
			return 1;
		}
	}
	return 0;
}
void work()
{
	scanf("%d",&n);
	for(int i=1;i<=n<<1;i++)
		e[i].clear(),ch[i]=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			a[i][j]=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			scanf("%d",&a[i][j]);
			e[a[i][j]+n].insert(i);
			e[i].insert(a[i][j]+n);
		}
	for(int _=1;_<=n;_++)
	{
		memset(ch,0,sizeof(ch));
		int res=0;
		for(int i=1;i<=n;i++)
		{
			memset(vis,0,sizeof(vis));
			res+=dfs(i);
		}
		for(int i=1;i<=n;i++)
		{
			e[i].erase(e[i].find(ch[i]));e[ch[i]].erase(e[ch[i]].find(i));
			for(int j=1;j<=n;j++)
				if(ch[i]-n==a[i][j])
				{
					a[i][j]=0;ans[i][_]=j;
					break;
				}
		}
	}
	printf("%d\n",n*(n-1)>>1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(i<j)printf("%d %d %d %d\n",i,ans[i][j],j,ans[j][i]);
	
}
int main()
{
	int _;scanf("%d",&_);
	while(_--)work();
	return 0;
}

详细

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 7ms
memory: 5716kb

input:

7
132
96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 ...

output:

8646
1 2 2 1
1 3 3 1
1 4 4 1
1 5 5 1
1 6 6 1
1 7 7 1
1 8 8 1
1 9 9 1
1 10 10 1
1 11 11 1
1 12 12 1
1 13 13 1
1 14 14 1
1 15 15 1
1 16 16 1
1 17 17 1
1 18 18 1
1 19 19 1
1 20 20 1
1 21 21 1
1 22 22 1
1 23 23 1
1 24 24 1
1 25 25 1
1 26 26 1
1 27 27 1
1 28 28 1
1 29 29 1
1 30 30 1
1 31 31 1
1 32 32 1
1...

result:

ok your solution is correct.

Test #2:

score: 0
Accepted
time: 3ms
memory: 4740kb

input:

8
14
13 13 13 13 13 13 13 13 13 13 13 13 13 13
7 7 7 7 7 7 7 7 7 7 7 7 7 7
8 8 8 8 8 8 8 8 8 8 8 8 8 8
14 14 14 14 14 14 14 14 14 14 14 14 14 14
5 5 5 5 5 5 5 5 5 5 5 5 5 5
4 4 4 4 4 4 4 4 4 4 4 4 4 4
1 1 1 1 1 1 1 1 1 1 1 1 1 1
10 10 10 10 10 10 10 10 10 10 10 10 10 10
2 2 2 2 2 2 2 2 2 2 2 2 2 2
9...

output:

91
1 2 2 1
1 3 3 1
1 4 4 1
1 5 5 1
1 6 6 1
1 7 7 1
1 8 8 1
1 9 9 1
1 10 10 1
1 11 11 1
1 12 12 1
1 13 13 1
1 14 14 1
2 3 3 2
2 4 4 2
2 5 5 2
2 6 6 2
2 7 7 2
2 8 8 2
2 9 9 2
2 10 10 2
2 11 11 2
2 12 12 2
2 13 13 2
2 14 14 2
3 4 4 3
3 5 5 3
3 6 6 3
3 7 7 3
3 8 8 3
3 9 9 3
3 10 10 3
3 11 11 3
3 12 12 3...

result:

ok your solution is correct.

Test #3:

score: 0
Accepted
time: 6ms
memory: 4816kb

input:

4
82
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 1...

output:

3321
1 2 2 1
1 3 3 1
1 4 4 1
1 5 5 1
1 6 6 1
1 7 7 1
1 8 8 1
1 9 9 1
1 10 10 1
1 11 11 1
1 12 12 1
1 13 13 1
1 14 14 1
1 15 15 1
1 16 16 1
1 17 17 1
1 18 18 1
1 19 19 1
1 20 20 1
1 21 21 1
1 22 22 1
1 23 23 1
1 24 24 1
1 25 25 1
1 26 26 1
1 27 27 1
1 28 28 1
1 29 29 1
1 30 30 1
1 31 31 1
1 32 32 1
1...

result:

ok your solution is correct.

Test #4:

score: 0
Accepted
time: 12ms
memory: 7372kb

input:

8
3
1 1 1
3 3 3
2 2 2
3
1 1 1
3 3 3
2 2 2
1
1
11
5 5 5 5 5 5 5 5 5 5 5
3 3 3 3 3 3 3 3 3 3 3
1 1 1 1 1 1 1 1 1 1 1
9 9 9 9 9 9 9 9 9 9 9
4 4 4 4 4 4 4 4 4 4 4
11 11 11 11 11 11 11 11 11 11 11
2 2 2 2 2 2 2 2 2 2 2
6 6 6 6 6 6 6 6 6 6 6
8 8 8 8 8 8 8 8 8 8 8
10 10 10 10 10 10 10 10 10 10 10
7 7 7 7 7...

output:

3
1 2 2 1
1 3 3 1
2 3 3 2
3
1 2 2 1
1 3 3 1
2 3 3 2
0
55
1 2 2 1
1 3 3 1
1 4 4 1
1 5 5 1
1 6 6 1
1 7 7 1
1 8 8 1
1 9 9 1
1 10 10 1
1 11 11 1
2 3 3 2
2 4 4 2
2 5 5 2
2 6 6 2
2 7 7 2
2 8 8 2
2 9 9 2
2 10 10 2
2 11 11 2
3 4 4 3
3 5 5 3
3 6 6 3
3 7 7 3
3 8 8 3
3 9 9 3
3 10 10 3
3 11 11 3
4 5 5 4
4 6 6 4...

result:

ok your solution is correct.

Subtask #2:

score: 20
Accepted

Dependency #1:

100%
Accepted

Test #5:

score: 20
Accepted
time: 8ms
memory: 6376kb

input:

5
17
9 9 9 9 9 9 9 9 9 9 9 9 9 2 9 9 9
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6
2 2 2 2 2 2 2 2 2 2 2 2 11 2 2 2 2
4 4 4 4 4 4 10 4 4 4 4 4 4 4 4 4 4
10 10 10 10 10 10 8 10 10 10 10 10 10 10 10 10 10
12 12 12 12 12 12 12 12 12 12 12 12 14 12 12 12 12
14 14 14 14 14 14 14 14 14 14 14 12 14 14 14 14 14
16 16...

output:

136
1 1 2 17
1 2 3 13
1 3 4 7
1 4 5 7
1 5 6 13
1 6 7 12
1 7 8 3
1 8 9 2
1 9 10 9
1 10 11 2
1 11 12 2
1 12 13 3
1 13 14 17
1 15 15 8
1 16 16 14
1 17 17 9
2 2 3 1
2 3 4 1
2 4 5 1
2 5 6 1
2 6 7 1
2 7 8 1
2 8 9 1
2 9 10 1
2 10 11 1
2 11 12 1
2 12 13 1
2 13 14 1
2 14 15 1
2 15 16 1
2 16 17 1
3 3 4 2
3 4 ...

result:

ok your solution is correct.

Test #6:

score: 0
Accepted
time: 7ms
memory: 5960kb

input:

9
1
1
28
2 2 2 2 5 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
7 24 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7
13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 8 13 13 13
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 16 8 8 8 8 8 8 8 8 8 8 8 8
17 24 24 24 24 24 24 24 24 24 24 24 24...

output:

0
378
1 1 2 2
1 2 3 25
1 3 4 16
1 4 5 1
1 6 6 9
1 7 7 1
1 8 8 11
1 9 9 3
1 10 10 19
1 11 11 1
1 12 12 21
1 13 13 4
1 14 14 17
1 15 15 21
1 16 16 23
1 17 17 14
1 18 18 26
1 19 19 7
1 20 20 10
1 21 21 28
1 22 22 2
1 23 23 4
1 24 24 12
1 25 25 15
1 26 26 24
1 27 27 1
1 28 28 10
2 3 3 1
2 4 4 1
2 5 5 2
...

result:

ok your solution is correct.

Test #7:

score: 0
Accepted
time: 11ms
memory: 5592kb

input:

9
22
19 19 19 19 19 19 19 19 19 10 19 19 19 19 19 19 19 19 19 19 19 19
17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 8
21 21 21 21 21 21 21 21 5 21 21 21 21 21 21 21 21 21 21 21 21 21
12 12 12 12 12 12 12 22 12 12 12 12 12 12 12 12 12 12 12 12 12 12
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3...

output:

231
1 2 2 1
1 3 3 1
1 4 4 8
1 5 5 1
1 6 6 1
1 7 7 1
1 8 8 21
1 9 9 1
1 11 10 1
1 12 11 1
1 13 12 1
1 14 13 1
1 15 14 1
1 16 15 1
1 17 16 1
1 18 17 1
1 19 18 1
1 20 19 1
1 21 20 1
1 22 21 1
1 10 22 1
2 3 3 2
2 4 4 1
2 5 5 2
2 6 6 2
2 7 7 3
2 8 8 1
2 9 9 2
2 10 10 2
2 11 11 2
2 12 12 2
2 13 13 3
2 14 ...

result:

ok your solution is correct.

Test #8:

score: 0
Accepted
time: 7ms
memory: 4768kb

input:

8
29
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 6 3 3 3 3
11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 3 11 11 11 11 11 11 11 11
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 23 1 1 1 1 1 1 1
20 20 20 20 20 20 20 20 20 20 20 25 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
26 26...

output:

406
1 1 2 21
1 2 3 22
1 3 4 12
1 4 5 20
1 5 6 7
1 6 7 11
1 7 8 9
1 8 9 29
1 9 10 13
1 10 11 24
1 11 12 11
1 12 13 18
1 13 14 14
1 14 15 29
1 15 16 13
1 16 17 25
1 17 18 3
1 18 19 24
1 19 20 25
1 20 21 20
1 21 22 23
1 22 23 8
1 23 24 18
1 24 25 7
1 26 26 23
1 27 27 28
1 28 28 14
1 29 29 16
2 2 3 1
2 ...

result:

ok your solution is correct.

Subtask #3:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #9:

score: 60
Accepted
time: 4ms
memory: 3764kb

input:

19
1
1
2
1 2
1 2
3
1 3 2
2 3 1
2 1 3
4
1 4 3 4
3 2 2 1
3 1 2 3
4 4 1 2
5
4 2 1 5 4
4 5 4 4 1
5 3 2 3 2
3 1 3 2 1
3 1 2 5 5
6
6 2 2 1 6 6
2 5 5 3 4 6
1 2 4 2 6 1
4 4 1 4 5 1
1 2 6 5 3 5
5 3 3 3 3 4
7
5 2 3 6 4 2 7
2 1 6 1 1 5 2
1 6 7 7 5 1 2
6 6 3 4 4 7 1
3 6 5 7 3 2 7
3 2 5 1 4 5 4
5 3 3 7 4 4 6
8
1...

output:

0
1
1 1 2 1
3
1 1 2 1
1 3 3 2
2 3 3 1
6
1 4 2 1
1 3 3 3
1 1 4 3
2 2 3 1
2 3 4 4
3 4 4 1
10
1 3 2 2
1 4 3 2
1 2 4 4
1 5 5 2
2 3 3 1
2 4 4 1
2 5 5 3
3 4 4 2
3 5 5 1
4 3 5 4
15
1 5 2 1
1 6 3 1
1 4 4 1
1 2 5 4
1 3 6 2
2 2 3 2
2 3 4 3
2 6 5 6
2 4 6 3
3 5 4 2
3 6 5 1
3 3 6 4
4 5 5 2
4 6 6 5
5 3 6 6
21
1 2...

result:

ok your solution is correct.

Test #10:

score: 0
Accepted
time: 4ms
memory: 3732kb

input:

19
1
1
2
2 1
1 2
3
2 1 2
3 3 3
1 2 1
4
1 2 3 4
1 2 3 4
2 3 1 4
4 1 2 3
5
1 2 3 3 3
4 4 1 2 3
5 2 4 5 1
1 4 5 5 2
5 2 1 4 3
6
1 3 6 6 4 4
5 2 4 6 5 2
3 6 5 6 5 2
1 5 1 4 2 4
3 1 6 3 3 2
3 2 1 4 5 1
7
4 4 1 6 6 7 6
3 7 3 4 5 2 7
6 2 7 6 2 1 3
2 2 5 3 1 2 1
7 3 7 4 2 1 4
5 3 6 3 1 5 5
7 5 6 5 1 4 4
8
6...

output:

0
1
1 2 2 1
3
1 3 2 1
1 2 3 1
2 3 3 3
6
1 3 2 3
1 2 3 1
1 1 4 2
2 4 3 4
2 2 4 3
3 2 4 4
10
1 4 2 1
1 2 3 1
1 1 4 5
1 5 5 3
2 3 3 5
2 5 4 3
2 4 5 2
3 2 4 2
3 3 5 5
4 1 5 4
15
1 3 2 4
1 4 3 3
1 5 4 4
1 1 5 6
1 6 6 3
2 3 3 6
2 5 4 6
2 2 5 1
2 6 6 6
3 2 4 1
3 4 5 4
3 1 6 2
4 2 5 2
4 3 6 1
5 3 6 4
21
1 3...

result:

ok your solution is correct.

Test #11:

score: 0
Accepted
time: 3ms
memory: 3888kb

input:

19
1
1
2
2 1
1 2
3
3 3 2
1 1 2
2 1 3
4
4 1 1 3
4 4 1 2
1 2 2 3
3 2 4 3
5
3 1 5 5 5
4 2 2 5 2
1 5 4 3 4
1 1 3 4 4
3 1 2 3 2
6
1 5 5 3 2 1
5 5 2 3 4 3
2 6 2 3 1 4
6 6 6 4 6 1
4 5 1 2 3 4
6 3 2 4 5 1
7
5 1 1 3 3 7 7
5 4 1 4 4 3 6
4 4 2 7 1 3 2
1 3 5 6 5 3 5
6 4 2 7 6 2 3
7 2 6 2 1 6 2
5 7 4 5 7 1 6
8
1...

output:

0
1
1 2 2 1
3
1 2 2 3
1 3 3 2
2 2 3 1
6
1 2 2 3
1 3 3 4
1 4 4 2
2 2 3 2
2 4 4 1
3 1 4 4
10
1 4 2 2
1 1 3 3
1 5 4 3
1 2 5 2
2 4 3 4
2 3 4 1
2 5 5 3
3 1 4 2
3 2 5 5
4 5 5 1
15
1 3 2 4
1 1 3 6
1 5 4 1
1 4 5 4
1 6 6 6
2 1 3 5
2 2 4 2
2 5 5 1
2 3 6 3
3 2 4 3
3 3 5 6
3 4 6 2
4 5 5 5
4 4 6 4
5 2 6 5
21
1 4...

result:

ok your solution is correct.

Test #12:

score: 0
Accepted
time: 3ms
memory: 3644kb

input:

19
1
1
2
2 2
1 1
3
1 1 2
2 1 3
3 2 3
4
2 1 2 3
2 1 3 3
4 4 4 4
2 3 1 1
5
3 5 5 5 4
1 4 4 5 2
1 1 3 1 5
2 4 3 2 3
2 3 4 1 2
6
5 5 4 3 1 1
3 4 1 6 6 6
6 2 2 1 4 4
2 2 6 5 3 3
1 5 6 2 3 3
5 4 1 2 4 5
7
6 4 4 7 7 5 6
1 1 2 1 4 2 7
5 2 5 3 1 1 2
3 4 2 7 6 7 6
5 6 1 2 7 6 4
5 6 5 3 3 7 3
5 4 2 1 3 4 3
8
2...

output:

0
1
1 2 2 1
3
1 3 2 3
1 2 3 2
2 1 3 1
6
1 1 2 1
1 2 3 1
1 3 4 3
2 4 3 2
2 2 4 4
3 4 4 1
10
1 2 2 5
1 3 3 5
1 4 4 3
1 1 5 4
2 1 3 1
2 3 4 5
2 4 5 1
3 2 4 2
3 4 5 5
4 4 5 2
15
1 3 2 1
1 2 3 5
1 5 4 3
1 4 5 4
1 6 6 3
2 3 3 4
2 5 4 4
2 6 5 5
2 2 6 4
3 2 4 1
3 6 5 6
3 3 6 2
4 2 5 2
4 6 6 5
5 3 6 1
21
1 3...

result:

ok your solution is correct.

Test #13:

score: 0
Accepted
time: 49ms
memory: 6560kb

input:

5
156
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 95 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 34 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 14 17 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 130 1 42 1 1 1 1 1 1 1 1 1 1 1 1 90 1 64 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

12090
1 122 2 3
1 109 3 111
1 26 4 79
1 1 5 156
1 2 6 48
1 84 7 56
1 3 8 69
1 4 9 59
1 85 10 1
1 65 11 35
1 5 12 46
1 6 13 80
1 124 14 16
1 7 15 146
1 8 16 135
1 9 17 71
1 10 18 36
1 11 19 7
1 12 20 67
1 13 21 86
1 14 22 149
1 15 23 10
1 16 24 73
1 17 25 66
1 18 26 20
1 19 27 82
1 20 28 79
1 21 29 1...

result:

ok your solution is correct.

Test #14:

score: 0
Accepted
time: 31ms
memory: 5824kb

input:

7
2
1 2
1 2
4
1 4 4 1
2 3 2 4
1 4 3 3
3 1 2 2
39
1 31 38 1 22 35 1 32 36 19 33 1 1 1 4 14 24 35 33 4 1 31 34 1 1 27 1 1 34 8 35 1 1 38 10 1 6 8 10
22 14 2 2 2 20 9 26 2 8 26 23 2 36 36 2 38 2 2 18 27 29 3 28 2 3 31 33 36 2 20 2 11 33 32 2 2 2 32
34 39 11 34 35 3 3 3 16 3 3 3 34 39 3 27 17 30 33 11 3...

output:

1
1 1 2 1
6
1 3 2 1
1 1 3 3
1 4 4 2
2 4 3 1
2 3 4 3
3 2 4 4
741
1 2 2 27
1 22 3 19
1 18 4 29
1 8 5 12
1 10 6 11
1 3 7 18
1 34 8 35
1 23 9 4
1 29 10 25
1 11 11 18
1 17 12 33
1 19 13 21
1 31 14 3
1 9 15 7
1 26 16 2
1 5 17 25
1 37 18 5
1 35 19 28
1 39 20 2
1 16 21 4
1 1 22 23
1 4 23 33
1 30 24 16
1 15 ...

result:

ok your solution is correct.

Test #15:

score: 0
Accepted
time: 41ms
memory: 6764kb

input:

7
9
3 8 8 5 7 7 2 5 2
5 9 4 9 8 3 5 7 5
1 2 6 6 9 3 9 6 4
7 6 9 1 7 7 1 4 7
2 7 6 3 8 1 2 9 8
3 8 2 2 4 6 1 6 1
1 5 2 6 4 8 4 6 4
9 3 3 9 9 1 3 7 8
4 1 4 8 5 5 3 2 5
8
8 4 7 2 1 7 3 2
2 2 8 7 6 3 5 6
8 8 1 7 5 8 1 5
2 8 5 1 7 3 1 2
4 1 3 6 6 3 7 8
4 2 3 6 1 5 5 2
4 7 4 3 7 4 6 3
6 6 5 1 5 4 8 4
2
1 ...

output:

36
1 5 2 5
1 8 3 5
1 6 4 2
1 1 5 2
1 2 6 3
1 7 7 5
1 3 8 2
1 9 9 2
2 3 3 3
2 7 4 3
2 2 5 5
2 6 6 5
2 8 7 1
2 4 8 3
2 9 9 8
3 2 4 1
3 4 5 6
3 9 6 6
3 8 7 3
3 6 8 9
3 1 9 7
4 7 5 8
4 5 6 2
4 8 7 4
4 6 8 7
4 9 9 1
5 1 6 4
5 4 7 2
5 7 8 8
5 3 9 3
6 9 7 8
6 8 8 1
6 1 9 5
7 7 8 4
7 9 9 6
8 5 9 9
28
1 5 2 ...

result:

ok your solution is correct.

Test #16:

score: 0
Accepted
time: 36ms
memory: 5376kb

input:

9
8
8 7 6 6 2 2 6 2
5 1 6 5 5 4 1 2
5 3 8 1 2 2 4 3
5 4 7 8 7 1 7 1
6 4 8 4 1 6 8 3
3 3 1 8 3 5 4 3
7 6 5 2 7 3 6 8
8 4 7 2 1 7 5 4
6
3 3 6 2 5 2
5 5 4 4 6 1
6 4 1 3 2 4
3 5 3 6 3 1
4 2 2 1 6 5
1 6 5 4 1 2
118
1 18 1 1 1 1 1 1 4 1 115 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 5 1 1 1 1 1 1 18 62 1 1 1 1 1 1 1...

output:

28
1 3 2 1
1 1 3 5
1 4 4 4
1 5 5 1
1 7 6 7
1 6 7 6
1 8 8 5
2 4 3 2
2 8 4 3
2 6 5 2
2 7 6 4
2 5 7 3
2 3 8 4
3 4 4 5
3 8 5 5
3 3 6 1
3 7 7 2
3 1 8 2
4 7 5 3
4 2 6 2
4 6 7 1
4 8 8 8
5 8 6 3
5 7 7 8
5 4 8 7
6 5 7 4
6 8 8 3
7 5 8 6
15
1 2 2 3
1 3 3 1
1 5 4 2
1 4 5 2
1 6 6 1
2 2 3 2
2 6 4 4
2 5 5 3
2 4 6 ...

result:

ok your solution is correct.

Test #17:

score: -60
Time Limit Exceeded

input:

1
200
10 98 86 3 124 117 19 6 74 143 48 196 32 33 15 5 23 56 138 65 150 46 125 157 43 162 48 141 161 93 179 175 163 1 144 183 105 65 158 195 102 112 69 194 142 177 182 135 60 77 140 117 47 171 5 157 14 115 17 163 130 55 134 74 10 108 117 181 75 154 14 138 106 60 127 25 162 196 172 156 66 41 20 127 1...

output:


result: