UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#203947#2008. crossingtkswls100700ms6168kbC++111.2kb2024-03-30 11:05:022024-03-30 17:12:49

answer

#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
int n, m, head[100005], nxt[200005], to[200005], w[200005], ccnt, minn = 0x3f3f3f3f, dis[200005];
vector<pair<int, int>> son[100005];
inline void add(int p, int q, int ww) {
//	cout << p << " " << q << " " << ww << "\n";
	nxt[++ccnt] = head[p];
	to[ccnt] = q;
	w[ccnt] = ww;
	head[p] = ccnt;
}
inline void dfs(int p) {
	for (int &i = head[p]; i; i = nxt[i]) {
		if (dis[to[i]]) {
			minn = min(minn, dis[p] - dis[to[i]] + w[i]);
		} else {
			dis[to[i]] = dis[p] + w[i];
			dfs(to[i]);
		}
	}
	dis[p] = 0;
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	int p;
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			cin >> p;
			son[j].push_back(make_pair(p, i));
		}
	}
	for (int i = 1; i <= n; i++) {
		sort(son[i].begin(), son[i].end());
		for (int j = 1; j <= m - 1; j++) {
			if (son[i][j - 1].first && son[i][j].first) {
				add(son[i][j - 1].second, son[i][j].second, son[i][j].first - son[i][j - 1].first);
			}
		}
	}
	dis[1] = 1;
	dfs(1);
	if (minn == 0x3f3f3f3f) {
		cout << -1;
	} else {
		cout << minn;
	}
}

详细

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 7
Accepted

Test #1:

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

input:

2 300
472 0
330 0
145 1167
1186 565
198 1220
570 0
998 377
1102 481
57 1079
1506 885
1192 571
453 0
...

output:

1643

result:

ok single line: '1643'

Test #2:

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

input:

2 300
0 719
2510 0
0 833
1259 0
290 2242
1793 0
1597 0
950 0
1257 0
2178 0
1583 0
0 1177
3882 0
0 13...

output:

5951

result:

ok single line: '5951'

Test #3:

score: 0
Accepted
time: 26ms
memory: 6168kb

input:

2 50000
1691 4232
1523 4064
0 794
2355 0
4419 0
0 2340
3944 0
925 3466
3078 0
0 1539
1982 0
2783 0
1...

output:

7215

result:

ok single line: '7215'

Test #4:

score: 0
Accepted
time: 28ms
memory: 6168kb

input:

2 50000
4093 7762
537 4206
3828 7497
0 3400
0 1105
0 772
0 1986
933 4602
0 3435
0 604
449 4118
0 326...

output:

9218

result:

ok single line: '9218'

Test #5:

score: 0
Accepted
time: 22ms
memory: 5412kb

input:

2 44705
479 0
3690 0
0 557
2005 0
4210 0
0 2904
0 2090
0 3387
0 3606
0 1508
0 6059
0 5914
2190 0
0 3...

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

2 50000
1063 0
700 3804
1073 0
0 1846
0 1051
0 2573
0 2372
0 1988
1883 296
2161 574
2308 721
150 325...

output:

4691

result:

ok single line: '4691'

Subtask #2:

score: 7
Accepted

Test #7:

score: 7
Accepted
time: 23ms
memory: 5404kb

input:

50000 2
658 314 457 285 331 0 0 0 39 0 194 0 0 0 222 123 40 0 56 0 0 8 0 473 0 651 0 117 0 0 458 414...

output:

1032

result:

ok single line: '1032'

Test #8:

score: 0
Accepted
time: 17ms
memory: 5472kb

input:

50000 2
0 0 0 1497 1229 0 1489 777 570 77 1176 1871 0 434 1432 0 1112 0 1392 102 0 0 0 0 1829 1124 2...

output:

-1

result:

ok single line: '-1'

Test #9:

score: 0
Accepted
time: 16ms
memory: 5464kb

input:

50000 2
2400 0 960 0 913 2504 0 2337 4005 0 1817 1041 2094 3045 1369 0 718 1263 0 406 995 2178 497 0...

output:

4404

result:

ok single line: '4404'

Test #10:

score: 0
Accepted
time: 19ms
memory: 5416kb

input:

50000 2
947 0 3062 3961 0 0 0 1676 0 0 2726 0 2592 5842 0 0 2766 853 0 154 0 3466 3813 2766 0 0 0 35...

output:

7343

result:

ok single line: '7343'

Test #11:

score: 0
Accepted
time: 21ms
memory: 5244kb

input:

50000 2
0 0 0 2945 0 0 172 0 1208 0 0 2892 0 0 6424 2270 0 0 0 0 8392 3242 0 0 0 0 3687 4920 3458 0 ...

output:

12719

result:

ok single line: '12719'

Test #12:

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

input:

300 2
0 0 927 0 1520 1114 0 0 0 0 0 1695 0 0 0 0 311 0 0 0 1287 0 0 0 0 3069 0 951 0 1447 1371 0 106...

output:

4297

result:

ok single line: '4297'

Subtask #3:

score: 18
Accepted

Test #13:

score: 18
Accepted
time: 0ms
memory: 3616kb

input:

10 10
1687 1345 0 0 0 0 0 0 0 6911
0 0 0 4680 0 0 0 0 3969 0
0 0 0 0 0 3461 0 0 0 0
0 0 0 3878 0 0 0...

output:

-1

result:

ok single line: '-1'

Test #14:

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

input:

10 10
0 423 757 1381 0 0 0 3091 0 0
0 131 465 1089 0 0 0 2799 3538 0
0 2824 0 0 0 758 573 1507 2246 ...

output:

3985

result:

ok single line: '3985'

Test #15:

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

input:

10 10
0 3995 1562 7583 3661 0 0 0 0 0
0 0 0 79 0 1008 6002 6274 3288 0
0 0 8748 0 0 0 4704 4976 1990...

output:

15988

result:

ok single line: '15988'

Test #16:

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

input:

10 10
0 0 0 0 0 7039 0 5729 0 0
0 2092 0 0 0 0 0 0 0 3333
0 6103 0 0 0 2181 0 871 0 0
1349 0 0 0 0 9...

output:

17566

result:

ok single line: '17566'

Test #17:

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

input:

10 10
0 0 0 0 0 0 73 0 0 0
280 0 0 0 1005 660 1110 248 0 633
0 0 0 0 39 0 144 0 0 0
337 0 0 0 1062 7...

output:

-1

result:

ok single line: '-1'

Test #18:

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

input:

10 10
1982 0 0 0 0 706 0 0 2162 0
0 305 0 0 0 1129 0 0 0 0
1769 0 0 0 282 493 0 0 1949 0
1283 2086 0...

output:

2903

result:

ok single line: '2903'

Test #19:

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

input:

8 10
0 0 768 1167 0 0 0 4591
0 0 2071 0 616 237 0 0
0 223 2443 0 988 609 0 207
500 0 4037 0 0 2203 0...

output:

6059

result:

ok single line: '6059'

Test #20:

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

input:

10 8
5649 4949 3246 0 4374 0 5277 0 0 1072
0 5499 3796 0 4924 0 5827 0 0 1622
5705 5005 3302 0 4430 ...

output:

7637

result:

ok single line: '7637'

Subtask #4:

score: 36
Accepted

Test #21:

score: 36
Accepted
time: 11ms
memory: 4872kb

input:

300 300
0 0 2204 0 0 0 0 0 2006 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

94495

result:

ok single line: '94495'

Test #22:

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

input:

300 300
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

-1

result:

ok single line: '-1'

Test #23:

score: 0
Accepted
time: 10ms
memory: 4820kb

input:

300 300
0 0 0 0 0 0 0 0 0 0 0 1580 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

-1

result:

ok single line: '-1'

Test #24:

score: 0
Accepted
time: 10ms
memory: 4840kb

input:

300 300
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5162 0 0 0 0 0 0 0 0 0 0 0 0...

output:

230295

result:

ok single line: '230295'

Test #25:

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

input:

300 300
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2682...

output:

150474

result:

ok single line: '150474'

Test #26:

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

input:

300 300
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3404 0 0 0 0 0 0 0 0 0 0 0...

output:

193667

result:

ok single line: '193667'

Test #27:

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

input:

200 300
0 0 0 0 0 0 3097 2859 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 659 0 0 0 ...

output:

113560

result:

ok single line: '113560'

Test #28:

score: 0
Accepted
time: 8ms
memory: 4236kb

input:

300 200
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7103 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

132623

result:

ok single line: '132623'

Test #29:

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

input:

300 242
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

-1

result:

ok single line: '-1'

Test #30:

score: 0
Accepted
time: 10ms
memory: 4828kb

input:

300 300
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 398 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

-1

result:

ok single line: '-1'

Test #31:

score: 0
Accepted
time: 10ms
memory: 4828kb

input:

300 300
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 77...

output:

350894

result:

ok single line: '350894'

Test #32:

score: 0
Accepted
time: 5ms
memory: 4436kb

input:

200 300
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

199316

result:

ok single line: '199316'

Test #33:

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

input:

300 300
0 5214 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

223458

result:

ok single line: '223458'

Test #34:

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

input:

300 300
8 859 1710 2561 3412 4263 5114 0 6816 0 8518 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

255562

result:

ok single line: '255562'

Test #35:

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

input:

300 300
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

104271

result:

ok single line: '104271'

Test #36:

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

input:

300 300
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

-1

result:

ok single line: '-1'

Test #37:

score: 0
Accepted
time: 8ms
memory: 4836kb

input:

300 300
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

245137

result:

ok single line: '245137'

Test #38:

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

input:

300 300
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

281478

result:

ok single line: '281478'

Test #39:

score: 0
Accepted
time: 9ms
memory: 4860kb

input:

300 300
0 0 2541 0 0 0 0 0 0 0 3866 0 0 0 0 2304 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

115238

result:

ok single line: '115238'

Test #40:

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

input:

300 300
0 0 0 0 0 0 0 0 0 0 0 1025 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

158177

result:

ok single line: '158177'

Test #41:

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

input:

300 300
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

177241

result:

ok single line: '177241'

Subtask #5:

score: 32
Accepted

Test #42:

score: 32
Accepted
time: 9ms
memory: 4428kb

input:

200 500
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 94 2018 0 0 0 0 0 ...

output:

-1

result:

ok single line: '-1'

Test #43:

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

input:

200 500
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3788 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

267237

result:

ok single line: '267237'

Test #44:

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

input:

100 1000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 884 8210 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 988 ...

output:

87670

result:

ok single line: '87670'

Test #45:

score: 0
Accepted
time: 8ms
memory: 4500kb

input:

100 1000
0 2299 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3772 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5...

output:

89456

result:

ok single line: '89456'

Test #46:

score: 0
Accepted
time: 14ms
memory: 5068kb

input:

10 10000
0 0 286 119 1313 0 0 0 0 0
0 0 0 0 0 0 5070 0 0 0
0 0 0 0 0 0 2843 0 0 0
0 0 0 0 0 0 1780 0...

output:

25334

result:

ok single line: '25334'

Test #47:

score: 0
Accepted
time: 9ms
memory: 5072kb

input:

10 10000
0 0 0 0 2820 0 0 0 0 0
3466 0 0 0 0 0 0 0 0 0
0 0 0 0 0 742 0 0 0 0
0 0 0 0 0 5351 0 0 0 0
...

output:

44398

result:

ok single line: '44398'

Test #48:

score: 0
Accepted
time: 9ms
memory: 5084kb

input:

20 5000
0 538 0 0 0 0 3148 0 0 0 0 0 833 0 0 0 0 0 0 2720
5696 0 0 0 0 5490 0 0 0 0 0 7642 0 0 0 0 0...

output:

31854

result:

ok single line: '31854'

Test #49:

score: 0
Accepted
time: 10ms
memory: 4972kb

input:

20 5000
0 0 0 0 1597 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 4269 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5695 0 0 0
0 0...

output:

66409

result:

ok single line: '66409'

Test #50:

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

input:

5 20000
0 0 1900 0 0
0 3513 0 0 0
1822 0 0 0 495
0 0 3600 0 0
0 2002 0 0 0
1675 0 0 0 348
0 6330 0 0...

output:

22388

result:

ok single line: '22388'

Test #51:

score: 0
Accepted
time: 20ms
memory: 5564kb

input:

5 20000
0 5112 2375 0 4282
2365 2091 0 3028 1261
0 6061 3324 55 5231
0 5490 2753 0 4660
0 6466 3729 ...

output:

6943

result:

ok single line: '6943'

Test #52:

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

input:

500 200
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

-1

result:

ok single line: '-1'

Test #53:

score: 0
Accepted
time: 8ms
memory: 4664kb

input:

500 200
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 177 5109 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

119340

result:

ok single line: '119340'

Test #54:

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

input:

500 200
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7010 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

188195

result:

ok single line: '188195'

Test #55:

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

input:

1000 100
0 0 0 0 0 0 4569 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7674 0 0 0 0 0 0 0 0 0 0 0 0...

output:

80638

result:

ok single line: '80638'

Test #56:

score: 0
Accepted
time: 13ms
memory: 5536kb

input:

10000 10
0 41 0 0 0 0 33 0 0 197 15 0 0 0 0 0 33 0 0 152 0 136 0 81 193 0 0 0 0 0 54 198 56 9 0 39 0...

output:

277

result:

ok single line: '277'

Test #57:

score: 0
Accepted
time: 14ms
memory: 5524kb

input:

10000 10
8463 6528 2870 0 0 0 706 5701 3388 1603 0 0 1716 0 0 2633 0 0 0 0 6549 5247 2862 0 0 619 0 ...

output:

10702

result:

ok single line: '10702'

Test #58:

score: 0
Accepted
time: 8ms
memory: 5264kb

input:

10000 10
0 0 0 0 0 946 0 0 0 2374 0 0 3270 0 0 0 2707 0 0 0 6093 0 0 0 3637 0 0 0 0 0 4356 0 0 0 256...

output:

20709

result:

ok single line: '20709'

Test #59:

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

input:

5000 20
3740 0 0 0 1380 0 0 0 0 1837 0 0 1915 0 0 266 0 0 526 4038 0 0 2159 0 0 2706 0 0 0 3490 0 0 ...

output:

17013

result:

ok single line: '17013'

Test #60:

score: 0
Accepted
time: 15ms
memory: 5240kb

input:

5000 20
0 5199 0 0 0 0 4533 0 4855 0 0 0 546 2746 0 0 0 0 0 3014 0 0 0 4680 0 0 0 1334 0 1620 0 0 0 ...

output:

17972

result:

ok single line: '17972'

Test #61:

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

input:

5000 20
0 5100 0 0 0 0 0 0 0 3991 0 0 0 0 0 0 1541 0 0 0 0 0 0 0 63 2714 0 0 0 0 0 0 0 0 1937 0 0 0 ...

output:

45212

result:

ok single line: '45212'

Test #62:

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

input:

20000 5
0 0 0 8397 0 2887 0 0 0 8143 0 0 468 0 931 0 2772 0 0 4787 0 1842 0 0 6096 3356 0 0 4678 0 0...

output:

12497

result:

ok single line: '12497'

Test #63:

score: 0
Accepted
time: 9ms
memory: 5308kb

input:

20000 5
0 0 0 0 0 431 8900 0 0 0 580 5411 0 0 0 0 0 0 2956 0 0 0 0 0 0 1709 0 0 0 0 0 5761 0 0 0 0 0...

output:

-1

result:

ok single line: '-1'

Test #64:

score: 0
Accepted
time: 10ms
memory: 5304kb

input:

20000 5
0 0 0 0 0 0 4470 0 285 0 1493 0 0 0 0 0 3762 0 0 0 0 5556 0 0 0 0 2527 0 0 0 0 802 0 0 0 0 3...

output:

21739

result:

ok single line: '21739'

Test #65:

score: 0
Accepted
time: 13ms
memory: 5316kb

input:

20000 5
0 0 0 0 0 5248 0 0 1405 0 0 0 0 0 938 0 0 0 0 0 4822 0 0 0 0 155 733 0 0 0 0 0 0 0 1645 0 0 ...

output:

23317

result:

ok single line: '23317'

Test #66:

score: 0
Accepted
time: 14ms
memory: 5400kb

input:

20000 5
0 0 2258 0 754 0 0 0 3613 0 793 0 2249 0 0 3440 4114 0 5517 0 0 0 2724 920 0 0 0 0 0 0 0 0 0...

output:

16504

result:

ok single line: '16504'

Test #67:

score: 0
Accepted
time: 10ms
memory: 5204kb

input:

10000 10
0 0 0 0 816 0 0 0 0 0 0 0 0 0 0 0 0 0 4180 0 0 0 0 0 7055 0 0 895 4882 0 0 0 0 7572 0 1461 ...

output:

25531

result:

ok single line: '25531'

Test #68:

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

input:

5000 20
0 0 0 0 0 0 0 0 2020 0 2288 0 0 0 1931 0 0 0 0 0 0 0 0 0 0 0 0 4684 0 0 0 0 0 0 0 0 0 6586 0...

output:

44594

result:

ok single line: '44594'

Test #69:

score: 0
Accepted
time: 13ms
memory: 5068kb

input:

5000 20
4031 0 0 0 0 0 0 0 0 0 0 0 0 0 2687 0 0 0 0 276 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

39111

result:

ok single line: '39111'

Test #70:

score: 0
Accepted
time: 16ms
memory: 5220kb

input:

5 20000
3365 0 5045 0 0
0 997 0 480 0
3989 0 5669 0 0
2718 0 4398 0 0
5575 0 7255 0 0
1085 0 2765 0 ...

output:

11568

result:

ok single line: '11568'

Test #71:

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

input:

10 10000
0 442 0 2016 7155 0 0 0 1485 0
0 663 0 2237 7376 0 0 0 1706 0
0 0 0 0 4444 0 0 0 0 0
0 4494...

output:

18074

result:

ok single line: '18074'

Test #72:

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

input:

20 5000
0 0 0 2594 0 5839 0 0 0 4268 0 7396 0 0 0 0 0 0 1178 0
0 0 0 3688 0 6933 0 0 0 5362 0 8490 0...

output:

27873

result:

ok single line: '27873'

Extra Test:

score: 0
Extra Test Passed