QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#116100#5280. Depot Rearrangementyoungsystem#37 104ms21192kbC++202.8kb2023-06-28 09:35:272024-05-31 14:20:35

Judging History

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

  • [2024-05-31 14:20:35]
  • 评测
  • 测评结果:37
  • 用时:104ms
  • 内存:21192kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-28 09:35:27]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int n=0,f=1,ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		n=n*10+ch-'0';
		ch=getchar();
	}
	return n*f;
}
int p[200005];
int sl[200005];
bool cz[200005],vis[200005];
vector<int>v[200005];
vector<int>yy[405],qs[405];
int fa[200005];
int findf(int n)
{
	if(fa[n]==n)return n;
	return fa[n]=findf(fa[n]);
}
int xl1[200005],cnt1;
int xl2[200005],cnt2;
bool visd[200005];
int n,m;
void dfs(int x)
{
	if(visd[x])return;
	visd[x]=true;
	vector<int>v1;
	for(int i=1;i<=n;i++)
	{
		v1.clear();
		for(int j=0;j<yy[i].size();j++)
		{
			if(yy[i][j]==x)v1.push_back(j);
		}
		for(int j=0;j<qs[i].size();j++)
		{
			if(qs[i][j]==0)continue;
			if(!visd[qs[i][j]]&&!v1.empty())
			{
				//printf("%d %d\n",x,qs[i][j]);
				v[x].push_back(qs[i][j]);
				int sth=qs[i][j];
				yy[i][v1[v1.size()-1]]=0;
				qs[i][j]=0;
				v1.pop_back();
				dfs(sth);
			}
		}
	}
}
vector<int>wz[200005];
int now[1000005];
int sta[1000005],ttop;
void dfs1(int x)
{
	for(int i=now[x];i<v[x].size();i=now[x])
	{
		now[x]=i+1;
		dfs1(v[x][i]);
	}
	sta[++ttop]=x;
}
int main()
{
	n=read();
	m=read();
	for(int i=1;i<=n*m;i++)
	{
		p[i]=read();
	}
	for(int i=1;i<=m;i++)fa[i]=i;
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)sl[j]=0;
		for(int j=1;j<=m;j++)
		{
			sl[p[(i-1)*m+j]]++;
			if(sl[p[(i-1)*m+j]]>=2)
			{
				cz[p[(i-1)*m+j]]=true;
				yy[i].push_back(p[(i-1)*m+j]);
				wz[p[(i-1)*m+j]].push_back((i-1)*m+j);
			}
		}
		for(int j=1;j<=m;j++)if(sl[j]==0)qs[i].push_back(j);
		if(!yy[i].empty())
		{
			for(int j=1;j<yy[i].size();j++)fa[findf(yy[i][0])]=findf(yy[i][j]);
			for(int j=0;j<qs[i].size();j++)fa[findf(yy[i][0])]=findf(qs[i][j]);
		}
	} 
	for(int j=1;j<=m;j++)
	{
		if(cz[j]==false)continue;
		if(findf(j)==j)
		{
			v[m+1].push_back(j);
			v[j].push_back(m+1);
			dfs(j);
		}
	}
	for(int i=1;i<=n;i++)
	{
		cnt1=cnt2=0;
		for(int j=0;j<yy[i].size();j++)
		{
			if(yy[i][j]!=0)xl1[++cnt1]=yy[i][j];
		}
		for(int j=0;j<qs[i].size();j++)
		{
			if(qs[i][j]!=0)xl2[++cnt2]=qs[i][j];
		}
		for(int j=1;j<=cnt1;j++)
		{
			v[xl1[j]].push_back(xl2[j]);
		}
	}
	dfs1(m+1);
	reverse(sta+1,sta+ttop+1);
	//for(int i=1;i<=ttop;i++)printf("%d ",sta[i]);
	//printf("\n");
	for(int i=1;i<=ttop;i++)
	{
		if(sta[i]==m+1)sta[i]=n*m+1;
		else
		{
			if(wz[sta[i]].empty())
			{
				sta[i]=0;
				continue;
			}
			int sth=sta[i];
			sta[i]=wz[sth][wz[sth].size()-1];
			wz[sth].pop_back();
		}
	}
	//for(int i=1;i<=ttop;i++)printf("%d ",sta[i]);
	//printf("\n");
	cnt1=0;
	for(int i=1;i<=ttop;i++)if(sta[i]!=0)sta[++cnt1]=sta[i];
	printf("%d\n",cnt1-1);
	for(int i=cnt1;i>=2;i--)printf("%d %d\n",sta[i-1],sta[i]);
	return 0;
}

详细

Test #1:

score: 5
Accepted
time: 1ms
memory: 7840kb

input:

10 3
1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3


output:

0

result:

ok both subtasks are correct!

Test #2:

score: 2
Acceptable Answer
time: 1ms
memory: 7844kb

input:

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


output:

13
2 21
7 2
12 7
3 12
14 3
18 14
8 18
19 8
15 19
10 15
4 10
20 4
21 20

result:

points 0.40 first subtask is correct but plan is wrong.

Test #3:

score: 2
Acceptable Answer
time: 1ms
memory: 7848kb

input:

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


output:

32
18 101
28 18
39 28
16 39
6 16
44 6
29 44
43 29
56 43
36 56
38 36
30 38
20 30
66 20
58 66
3 58
75 3
50 75
49 50
95 49
26 95
90 26
89 90
27 89
87 27
67 87
100 67
55 100
76 55
97 76
79 97
101 79

result:

points 0.40 first subtask is correct but plan is wrong.

Test #4:

score: 2
Acceptable Answer
time: 1ms
memory: 7860kb

input:

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

output:

19
707 1001
747 707
1001 747
830 1001
175 830
210 175
109 210
734 109
184 734
453 184
359 453
775 359
670 775
850 670
949 850
819 949
713 819
814 713
1001 814

result:

points 0.40 first subtask is correct but plan is wrong.

Test #5:

score: 0
Wrong Answer
time: 1ms
memory: 8024kb

input:

200 100
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...

output:

193
1178 20001
9278 1178
20001 9278
3784 20001
5599 3784
6330 5599
16836 6330
5773 16836
3798 5773
17989 3798
4889 17989
7398 4889
8977 7398
8598 8977
5065 8598
16998 5065
6129 16998
12730 6129
16367 12730
12991 16367
16854 12991
7854 16854
459 7854
3158 459
4647 3158
11555 4647
2648 11555
16555 264...

result:

wrong answer first subtask is incorrect

Test #6:

score: 2
Acceptable Answer
time: 2ms
memory: 10084kb

input:

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

output:

1401
59 4021
28 59
60 28
70 60
112 70
37 112
33 37
11 33
29 11
38 29
12 38
57 12
4 57
92 4
106 92
95 106
39 95
19 39
196 19
18 196
94 18
34 94
20 34
76 20
53 76
129 53
149 129
36 149
40 36
88 40
219 88
80 219
150 80
55 150
260 55
176 260
320 176
74 320
119 74
115 119
84 115
79 84
180 79
169 180
255 ...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #7:

score: 0
Wrong Answer
time: 0ms
memory: 10032kb

input:

300 300
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...

output:

183
30900 90001
59100 30900
90001 59100
28482 90001
57282 28482
90001 57282
34753 90001
64753 34753
90001 64753
45855 90001
47655 45855
90001 47655
85045 90001
39145 85045
34499 39145
63443 34499
33143 63443
63494 33143
38688 63494
39588 38688
38476 39588
15076 38476
34177 15076
14303 34177
8603 143...

result:

wrong answer first subtask is incorrect

Test #8:

score: 2
Acceptable Answer
time: 4ms
memory: 10908kb

input:

301 40
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 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 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 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...

output:

11624
5420 12041
11440 5420
4818 11440
5119 4818
11442 5119
11741 11442
6022 11741
6323 6022
2 6323
303 2
6624 303
3 6624
6625 3
6925 6625
7527 6925
1207 7527
1507 1207
7828 1507
1208 7828
7829 1208
8129 7829
1808 8129
2109 1808
8430 2109
1809 8430
8431 1809
8731 8431
2410 8731
9634 2410
3012 9634
9...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #9:

score: 2
Acceptable Answer
time: 7ms
memory: 9188kb

input:

400 100
11 65 1 79 15 18 79 46 9 30 71 53 58 55 94 73 39 16 6 91 49 30 23 30 28 81 90 48 97 54 79 30 94 18 42 77 44 36 5 48 55 97 79 36 41 59 79 71 32 59 3 10 63 52 44 41 9 46 31 31 56 87 60 80 12 51 15 78 41 65 95 34 29 83 46 64 37 53 98 17 41 45 36 73 20 53 48 80 57 54 57 72 39 56 98 6 10 78 11 72...

output:

14592
513 40001
98 513
88 98
94 88
186 94
1974 186
177 1974
631 177
632 631
755 632
242 755
48 242
58 48
129 58
60 129
44 60
7 44
455 7
2383 455
528 2383
2391 528
196 2391
280 196
185 280
481 185
57 481
197 57
938 197
392 938
169 392
273 169
495 273
358 495
133 358
41 133
573 41
261 573
95 261
31 95...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #10:

score: 2
Acceptable Answer
time: 2ms
memory: 8056kb

input:

40 160
17 2 3 4 5 6 7 91 9 10 154 12 103 14 15 16 17 25 19 58 21 8 23 24 52 26 27 58 120 105 50 55 104 32 35 36 37 38 45 10 41 42 43 44 45 71 47 48 49 34 140 52 53 54 115 44 28 58 59 60 61 62 63 64 132 66 67 68 69 70 71 69 24 74 75 76 77 133 79 80 81 82 100 84 31 86 87 88 100 90 91 92 93 94 95 96 97...

output:

1316
2705 6401
636 2705
593 636
189 593
396 189
1066 396
1226 1066
132 1226
1269 132
752 1269
1254 752
446 1254
136 446
571 136
1695 571
1178 1695
302 1178
456 302
879 456
392 879
275 392
1440 275
781 1440
233 781
56 233
115 56
2674 115
143 2674
3634 143
241 3634
945 241
2835 945
939 2835
575 939
14...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #11:

score: 2
Acceptable Answer
time: 7ms
memory: 9188kb

input:

400 100
88 82 9 2 90 1 83 32 32 79 8 79 63 67 85 82 50 63 69 2 7 91 21 90 69 3 39 78 66 83 96 53 24 65 56 63 90 54 35 55 94 22 76 12 54 55 5 49 91 73 8 19 64 54 39 23 13 27 34 4 81 52 13 11 36 45 3 50 82 81 42 50 75 15 99 70 29 26 70 66 34 15 42 83 16 19 19 12 76 1 68 49 7 17 64 37 98 34 99 37 34 64...

output:

14611
88 40001
24 88
63 24
263 63
212 263
748 212
214 748
49 214
573 49
168 573
187 168
147 187
90 147
183 90
878 183
350 878
495 350
480 495
70 480
79 70
585 79
141 585
92 141
68 92
232 68
93 232
100 93
249 100
265 249
83 265
182 83
1689 182
700 1689
159 700
382 159
532 382
295 532
51 295
132 51
67...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #12:

score: 2
Acceptable Answer
time: 2ms
memory: 10216kb

input:

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

output:

4260
359 6021
174 359
95 174
37 95
843 37
1435 843
157 1435
1319 157
186 1319
1760 186
1515 1760
440 1515
1707 440
830 1707
197 830
230 197
1153 230
319 1153
2765 319
598 2765
522 598
3 522
1847 3
1535 1847
2737 1535
2251 2737
19 2251
1757 19
852 1757
3658 852
587 3658
4 587
678 4
789 678
4117 789
9...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #13:

score: 2
Acceptable Answer
time: 23ms
memory: 12280kb

input:

300 300
215 159 263 206 201 183 286 56 142 10 231 214 34 54 263 250 169 208 239 148 104 22 244 17 74 68 184 52 2 30 42 83 222 106 25 152 37 225 213 213 69 273 91 221 207 48 166 28 221 50 46 64 10 254 207 109 206 144 270 291 195 197 253 235 141 186 102 68 52 24 38 6 181 44 256 200 77 233 285 163 223 ...

output:

32648
112 90001
101 112
534 101
2207 534
480 2207
498 480
519 498
2034 519
1148 2034
447 1148
860 447
297 860
229 297
1151 229
88 1151
766 88
2229 766
1352 2229
2098 1352
486 2098
363 486
1785 363
588 1785
2030 588
15 2030
1490 15
201 1490
1291 201
2964 1291
4750 2964
471 4750
153 471
258 153
3495 2...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #14:

score: 2
Acceptable Answer
time: 58ms
memory: 15156kb

input:

201 400
1 1 1 1 1 152 1 1 1 1 1 1 1 33 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 300 154 1 1 147 1 1 1 383 186 1 1 90 256 1 1 1 1 1 1 1 63 1 1 1 1 208 1 1 1 1 31 1 1 1 1 1 1 1 127 1 1 29 216 397 393 1 1 1 1 1 1 279 1 1 1 1 55 1 1 215 249 1 1 1 1 1 1 172 1 1 1 1 1 1 1 1 1 1 1 1 349 1 331 1 1 1 1 1 1 1 34...

output:

63990
15724 80401
5039 15724
35059 5039
34697 35059
4501 34697
7806 4501
24721 7806
27853 24721
7554 27853
400 7554
51555 400
1541 51555
2391 1541
4399 2391
267 4399
1324 267
2848 1324
70955 2848
2210 70955
3167 2210
7985 3167
2787 7985
7916 2787
15247 7916
6642 15247
39175 6642
25922 39175
22551 25...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #15:

score: 0
Wrong Answer
time: 3ms
memory: 10572kb

input:

400 400
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...

output:

69
17567 160001
159167 17567
90797 159167
144797 90797
160001 144797
17152 160001
22752 17152
160001 22752
28968 160001
18968 28968
29150 18968
50350 29150
160001 50350
125947 160001
155547 125947
160001 155547
7538 160001
153866 7538
152264 153866
51864 152264
152266 51864
153938 152266
160001 1539...

result:

wrong answer first subtask is incorrect

Test #16:

score: 2
Acceptable Answer
time: 16ms
memory: 11664kb

input:

301 200
50 129 146 60 183 51 47 77 26 73 1 45 1 44 149 1 81 196 17 16 163 35 159 71 1 94 161 138 138 27 76 1 102 42 5 186 176 1 111 198 37 63 81 155 95 164 132 135 155 194 126 98 31 34 121 19 175 148 33 105 25 122 91 165 1 69 1 197 12 98 1 155 5 53 42 1 60 98 78 61 155 13 1 171 102 152 95 61 87 200 ...

output:

23506
88 60201
385 88
75 385
73 75
341 73
1055 341
150 1055
998 150
288 998
1350 288
167 1350
99 167
199 99
1343 199
197 1343
264 197
705 264
1977 705
137 1977
1741 137
2197 1741
332 2197
252 332
2965 252
1610 2965
361 1610
713 361
266 713
1613 266
1981 1613
518 1981
3685 518
535 3685
110 535
1688 1...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #17:

score: 2
Acceptable Answer
time: 69ms
memory: 15556kb

input:

201 400
1 1 1 1 1 1 1 1 1 1 1 1 1 263 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 246 1 1 1 1 1 1 1 1 1 1 1 1 1 1 107 1 1 1 1 1 1 1 1 57 1 1 1 1 1 1 1 224 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 90 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 ...

output:

77869
37790 80401
37187 37790
77990 37187
37388 77990
37589 37388
37991 37589
36785 37991
35177 36785
35579 35177
75578 35579
76583 75578
65729 76583
25328 65729
65931 25328
25329 65931
65528 25329
66131 65528
65328 66131
66132 65328
66533 66132
67337 66533
67739 67337
68543 67739
27740 68543
68342 ...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #18:

score: 2
Acceptable Answer
time: 37ms
memory: 13572kb

input:

400 300
75 26 289 176 131 196 124 8 230 157 247 265 13 2 210 141 17 200 187 83 21 22 118 144 232 26 284 75 48 30 132 32 65 34 72 36 73 286 164 40 41 261 65 270 221 12 139 48 49 143 91 39 17 258 275 56 151 194 282 55 228 266 296 64 22 232 67 142 69 152 10 102 109 45 75 49 283 112 78 283 81 236 169 22...

output:

43105
575 120001
1480 575
216 1480
1655 216
201 1655
122 201
507 122
3237 507
28 3237
894 28
759 894
2070 759
109 2070
283 109
789 283
2480 789
500 2480
2930 500
824 2930
758 824
890 758
743 890
1043 743
1122 1043
1661 1122
880 1661
1672 880
226 1672
755 226
250 755
3835 250
1663 3835
1453 1663
1690...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #19:

score: 2
Acceptable Answer
time: 104ms
memory: 21192kb

input:

333 399
1 1 1 1 1 1 1 28 1 1 1 1 1 1 161 1 17 1 1 1 1 262 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 43 1 1 1 1 1 70 1 1 1 142 1 1 1 1 1 1 1 1 1 1 1 1 70 1 1 1 1 1 1 278 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 245 1 1 1 1 1 1 33 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 106 1 1 1 1 268 1 1 1 172 1 1 1 1 1 312 1 286 1 1 1 1 ...

output:

114795
49286 132868
44292 49286
88412 44292
48620 88412
40686 48620
14350 40686
3538 14350
1333 3538
24951 1333
3964 24951
19929 3964
45956 19929
8758 45956
9672 8758
1412 9672
25261 1412
30918 25261
42008 30918
29920 42008
14729 29920
81366 14729
37737 81366
63938 37737
53282 63938
5866 53282
13751...

result:

points 0.40 first subtask is correct but plan is wrong.

Test #20:

score: 2
Acceptable Answer
time: 53ms
memory: 13052kb

input:

400 400
100 35 353 385 317 228 7 148 113 165 11 306 209 89 21 166 17 2 19 249 27 305 377 22 3 353 38 28 29 96 191 32 33 309 35 308 100 176 152 40 176 42 43 86 45 46 96 48 396 381 218 246 53 54 334 159 243 360 294 60 33 62 185 64 65 66 191 121 351 107 10 343 367 74 75 201 77 247 79 134 304 92 42 126 ...

output:

55816
1838 160001
1134 1838
2744 1134
2144 2744
589 2144
988 589
1598 988
260 1598
248 260
341 248
997 341
4036 997
3158 4036
181 3158
228 181
765 228
2382 765
1131 2382
2306 1131
3918 2306
1715 3918
3822 1715
268 3822
41 268
273 41
2261 273
4302 2261
3004 4302
1584 3004
957 1584
767 957
397 767
211...

result:

points 0.40 first subtask is correct but plan is wrong.