QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#338908#4946. 青蕈领主zlt100 ✓645ms10852kbC++143.7kb2024-02-26 14:39:322024-02-26 14:39:32

Judging History

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

  • [2024-02-26 14:39:32]
  • 评测
  • 测评结果:100
  • 用时:645ms
  • 内存:10852kb
  • [2024-02-26 14:39:32]
  • 提交

answer

// Problem: P4566 [CTSC2018] 青蕈领主
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P4566
// Memory Limit: 500 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))

using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;
typedef vector<ll> poly;

const int maxn = 500100;
const ll mod = 998244353, G = 3;

inline ll qpow(ll b, ll p) {
	ll res = 1;
	while (p) {
		if (p & 1) {
			res = res * b % mod;
		}
		b = b * b % mod;
		p >>= 1;
	}
	return res;
}

int r[maxn];

inline poly NTT(poly a, int op) {
	int n = (int)a.size();
	for (int i = 0; i < n; ++i) {
		if (i < r[i]) {
			swap(a[i], a[r[i]]);
		}
	}
	for (int k = 1; k < n; k <<= 1) {
		ll wn = qpow(op == 1 ? G : qpow(G, mod - 2), (mod - 1) / (k << 1));
		vector<ll> pw(k);
		pw[0] = 1;
		for (int i = 1; i < k; ++i) {
			pw[i] = pw[i - 1] * wn % mod;
		}
		for (int i = 0; i < n; i += (k << 1)) {
			for (int j = 0; j < k; ++j) {
				ll x = a[i + j], y = pw[j] * a[i + j + k] % mod;
				a[i + j] = (x + y) % mod;
				a[i + j + k] = (x - y + mod) % mod;
			}
		}
	}
	if (op == -1) {
		ll inv = qpow(n, mod - 2);
		for (int i = 0; i < n; ++i) {
			a[i] = a[i] * inv % mod;
		}
	}
	return a;
}

inline poly operator * (poly a, poly b) {
	a = NTT(a, 1);
	b = NTT(b, 1);
	int n = (int)a.size();
	for (int i = 0; i < n; ++i) {
		a[i] = a[i] * b[i] % mod;
	}
	a = NTT(a, -1);
	return a;
}

inline poly mul(poly a, poly b) {
	int n = (int)a.size() - 1, m = (int)b.size() - 1, k = 0;
	while ((1 << k) <= n + m + 1) {
		++k;
	}
	for (int i = 1; i < (1 << k); ++i) {
		r[i] = (r[i >> 1] >> 1) | ((i & 1) << (k - 1));
	}
	poly A(1 << k), B(1 << k);
	for (int i = 0; i <= n; ++i) {
		A[i] = a[i];
	}
	for (int i = 0; i <= m; ++i) {
		B[i] = b[i];
	}
	poly res = A * B;
	res.resize(n + m + 1);
	return res;
}

ll n, a[maxn], f[maxn], ans;

void cdq(int l, int r) {
	if (l == r) {
		if (l > 1) {
			f[l] = (f[l] + (3 - l + mod) * f[l - 1]) % mod;
		}
		return;
	}
	int mid = (l + r) >> 1;
	cdq(l, mid);
	if (l == 1) {
		poly A(mid + 1), B(mid + 1);
		for (int i = l; i <= mid; ++i) {
			A[i] = f[i] * (i - 1) % mod;
			B[i] = f[i];
		}
		poly res = mul(A, B);
		for (int i = mid + 1; i <= r; ++i) {
			f[i] = (f[i] + res[i]) % mod;
		}
	} else {
		poly A(mid - l + 1), B(r - l + 1);
		for (int i = l; i <= mid; ++i) {
			A[i - l] = f[i] * (i - 1) % mod;
		}
		for (int i = 1; i <= r - l; ++i) {
			B[i] = f[i];
		}
		poly res = mul(A, B);
		for (int i = mid + 1; i <= r; ++i) {
			f[i] = (f[i] + res[i - l]) % mod;
		}
		A = poly(mid - l + 1);
		B = poly(r - l + 1);
		for (int i = l; i <= mid; ++i) {
			A[i - l] = f[i];
		}
		for (int i = 1; i <= r - l; ++i) {
			B[i] = f[i] * (i - 1) % mod;
		}
		res = mul(A, B);
		for (int i = mid + 1; i <= r; ++i) {
			f[i] = (f[i] + res[i - l]) % mod;
		}
	}
	cdq(mid + 1, r);
}

inline void init() {
	f[0] = 1;
	f[1] = 2;
	cdq(1, n - 1);
}

void dfs(int l, int r) {
	if (l == r) {
		return;
	}
	if (a[r] != l) {
		ans = 0;
		return;
	}
	int j = r, k = 0;
	for (int i = r - 1; i >= l; --i) {
		if (i + 1 == j) {
			j = a[i];
			dfs(j, i);
			++k;
		} else if (a[i] < j) {
			ans = 0;
		}
	}
	ans = ans * f[k] % mod;
}

void solve() {
	for (int i = 1; i <= n; ++i) {
		scanf("%lld", &a[i]);
		a[i] = i - a[i] + 1;
	}
	ans = 1;
	dfs(1, n);
	printf("%lld\n", ans);
}

int main() {
	int T = 1;
	scanf("%d%lld", &T, &n);
	init();
	while (T--) {
		solve();
	}
	return 0;
}

详细

Test #1:

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

input:

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

output:

64

result:

ok 1 number(s): "64"

Test #2:

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

input:

1 10
1 1 3 1 2 1 2 7 9 10

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

input:

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

output:

256
87360
2400
87360
128
2400
64
352
9600
704
704
128
128
128
2400
128
2400
2400
2400
64
128
1408
128
9600
443296
128
128
9600
9600
443296
0
443296
256
2400
0
64
87360
443296
443296
128
0
443296
0
256
443296
443296
1408
9600
128
443296
704
443296
0
443296
2400
704
443296
87360
2400
704
443296
87360
...

result:

ok 100 numbers

Test #4:

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

input:

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

output:

2400
352
9600
704
128
87360
64
2400
512
2400
0
128
256
443296
9600
2400
87360
0
443296
87360
87360
1408
64
2400
64
443296
256
64
128
352
443296
0
443296
128
0
0
704
443296
704
443296
9600
128
2400
9600
87360
352
128
443296
128
704
0
1408
128
9600
443296
704
2400
2400
443296
0
128
2400
443296
9600
35...

result:

ok 100 numbers

Test #5:

score: 5
Accepted
time: 2ms
memory: 8256kb

input:

1 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 10...

output:

731696071

result:

ok 1 number(s): "731696071"

Test #6:

score: 5
Accepted
time: 2ms
memory: 8276kb

input:

1 300
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:

654818711

result:

ok 1 number(s): "654818711"

Test #7:

score: 5
Accepted
time: 4ms
memory: 7988kb

input:

100 300
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 14 1 1 1 1 1 25 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 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 8 1 1 17 1...

output:

629582282
936488602
14854846
0
972850406
335643474
401801367
518359524
0
42431632
964390278
0
735641393
402072933
0
315498454
714104802
235533741
71997442
584545233
143385672
0
243017113
986234659
955040013
187506887
47264449
0
134183782
140053056
645326653
706116063
793388530
755635337
660249932
35...

result:

ok 100 numbers

Test #8:

score: 5
Accepted
time: 3ms
memory: 8268kb

input:

100 300
1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 16 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 9 1 1 1 1 46 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 7 1 13 1 1 1 1 21 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 2 12 1 40 1 1 1 1 1 1 1 1 1 1 ...

output:

213721346
242599023
719011592
0
422638207
728716801
710719728
177328520
0
443663955
995539661
0
0
0
582405109
301065834
482480764
189294107
882417753
263472408
583100647
887062292
558090353
374255923
176488287
958825157
132492749
27789769
297287037
0
0
2733249
643517198
0
20415575
953067857
74118762...

result:

ok 100 numbers

Test #9:

score: 5
Accepted
time: 2ms
memory: 8020kb

input:

1 997
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:

495842312

result:

ok 1 number(s): "495842312"

Test #10:

score: 5
Accepted
time: 11ms
memory: 7992kb

input:

100 1000
1 1 1 2 4 1 6 1 2 3 11 1 1 2 1 4 1 1 1 2 5 1 11 1 1 2 3 1 18 1 2 1 1 1 6 1 1 2 4 5 1 1 3 9 1 1 2 1 5 1 7 1 2 1 1 2 1 4 24 1 1 1 1 3 1 1 7 1 2 1 2 61 1 2 3 1 2 1 4 8 9 82 1 2 3 1 1 6 1 2 9 1 1 3 1 5 1 1 8 1 1 3 1 1 23 1 2 1 4 1 1 7 1 2 3 4 1 2 1 8 1 2 1 12 1 1 2 1 1 2 1 1 3 4 8 1 2 3 15 1 1 ...

output:

639441690
325951010
772826730
707904063
750757689
685150437
3586144
711874830
882896695
312252618
0
0
625591512
0
0
953293767
310960913
665863278
61999458
536746177
269479775
755348118
0
816896717
0
0
0
890648230
0
435292445
0
528885058
277580975
916252312
0
958726742
640472413
682980893
661293405
0...

result:

ok 100 numbers

Test #11:

score: 5
Accepted
time: 10ms
memory: 8024kb

input:

100 1000
1 1 1 2 3 1 1 3 1 2 6 1 1 12 1 1 3 4 1 2 1 1 1 3 4 1 9 1 1 29 1 2 1 4 1 2 1 1 1 1 3 5 7 1 1 1 3 1 2 16 1 2 1 4 1 1 2 3 1 2 6 8 9 1 1 16 1 1 3 40 1 2 3 74 1 1 1 2 1 2 1 4 1 1 11 1 2 3 1 2 6 1 2 3 4 1 1 3 1 9 10 1 2 3 4 1 1 1 2 3 5 1 2 1 1 11 1 2 1 2 5 1 7 8 34 1 2 37 1 2 1 1 1 49 1 1 1 2 4 6...

output:

0
0
706651534
439786013
0
70411622
0
0
0
835773719
0
0
0
107157784
27212808
568144383
407628078
308471256
890881779
0
0
0
0
389644399
0
452029310
55646018
0
183690719
0
0
0
0
609100480
611850278
81354283
0
89798335
375537513
0
902011601
957022140
0
903873199
0
276820482
0
247728618
866180585
4914605...

result:

ok 100 numbers

Test #12:

score: 5
Accepted
time: 7ms
memory: 8032kb

input:

100 1000
1 1 1 2 3 1 1 3 1 2 6 1 1 12 1 1 3 4 1 2 1 1 1 3 4 1 9 1 1 29 1 2 1 4 1 2 1 1 1 1 3 5 7 1 1 1 3 1 2 16 1 2 1 4 1 1 2 3 1 2 6 8 9 1 1 16 1 1 3 40 1 2 3 74 1 1 1 2 1 2 1 4 1 1 11 1 2 3 1 2 6 1 2 3 4 1 1 3 1 9 10 1 2 3 4 1 1 1 2 3 5 1 2 1 1 11 1 2 1 2 5 1 7 8 34 1 2 37 1 2 1 1 1 49 1 1 1 2 4 6...

output:

0
0
706651534
439786013
0
70411622
0
0
0
835773719
0
0
0
107157784
27212808
568144383
407628078
308471256
890881779
0
0
0
0
389644399
0
452029310
55646018
0
183690719
0
0
0
0
609100480
611850278
81354283
0
89798335
375537513
0
902011601
957022140
0
903873199
0
276820482
0
247728618
866180585
4914605...

result:

ok 100 numbers

Test #13:

score: 5
Accepted
time: 47ms
memory: 8112kb

input:

100 5000
1 1 1 2 4 1 1 7 1 1 3 1 2 1 2 1 9 1 2 1 2 1 6 1 17 1 19 1 1 1 2 1 1 1 1 7 1 1 1 39 1 1 1 2 1 2 1 6 48 1 1 51 1 1 2 1 4 5 1 2 1 1 1 6 1 13 1 1 2 1 4 1 1 3 1 10 1 1 3 1 15 1 2 1 2 3 1 1 36 1 1 1 2 3 1 1 1 7 1 1 2 1 4 1 1 1 1 10 1 20 1 2 1 1 3 1 1 66 1 1 1 2 3 1 1 1 2 4 1 1 1 1 5 1 17 1 1 1 4 ...

output:

0
292588696
344051249
351335346
0
985560804
0
0
744141033
0
318360253
509056631
897631526
210708530
0
282499786
0
0
298272534
0
866815275
708474811
0
0
533348880
0
0
0
496288915
0
288732736
613115755
275961405
582960568
0
777792174
304810404
835564816
0
809847872
0
0
890711747
27774048
0
838137435
8...

result:

ok 100 numbers

Test #14:

score: 5
Accepted
time: 52ms
memory: 8416kb

input:

100 5000
1 1 2 3 1 5 1 1 1 1 3 1 2 1 9 1 1 1 2 3 1 21 1 1 3 1 5 6 1 2 3 4 1 1 2 4 36 38 1 1 1 1 2 4 1 1 3 1 9 1 11 1 1 1 1 1 2 1 20 1 2 1 24 1 1 1 1 2 3 31 1 33 1 2 1 4 1 2 7 1 1 2 4 12 1 2 3 4 1 1 7 8 1 10 1 1 13 1 2 1 4 1 19 1 2 1 4 5 1 7 1 2 3 1 2 1 2 1 6 1 2 3 20 1 1 2 3 1 2 1 2 1 1 3 135 1 1 1 ...

output:

153322044
150492767
0
994490869
0
0
0
855074869
0
788845897
849135324
558695774
329454393
0
0
0
739924836
452723945
0
786225052
0
0
0
185397693
73624630
988094148
0
836735505
57947855
705987810
106069205
0
0
885756183
494461680
182794483
0
482961814
31686100
0
0
249571642
543812012
0
722599260
64625...

result:

ok 100 numbers

Test #15:

score: 5
Accepted
time: 52ms
memory: 8116kb

input:

100 5000
1 1 1 2 1 2 6 1 1 2 10 1 1 1 2 1 6 1 8 1 1 3 1 2 1 2 1 1 1 1 12 1 2 3 1 1 3 1 1 2 1 11 1 2 3 4 5 6 1 19 1 1 3 1 1 2 3 1 2 3 4 8 1 1 11 1 1 1 68 1 2 3 4 5 1 75 1 2 1 2 1 2 1 8 1 2 3 1 1 2 15 1 2 1 4 96 1 1 3 1 2 1 7 1 9 106 1 2 1 1 1 1 7 1 2 1 1 2 1 1 6 1 8 1 12 1 1 2 1 5 1 2 3 1 2 1 2 1 2 1...

output:

946701850
983965823
543510180
0
234696913
532101369
36100829
817231065
772588292
709229991
29442326
651065274
0
837031094
0
0
316959187
97361210
0
989103922
345758410
347379164
0
897533810
488460689
0
0
497682855
33909352
194898623
0
0
118515226
0
284902892
251441025
850822408
357498752
892873025
0
...

result:

ok 100 numbers

Test #16:

score: 5
Accepted
time: 51ms
memory: 8108kb

input:

100 5000
1 1 1 3 4 1 1 2 3 1 1 6 1 8 14 1 1 2 3 1 2 3 1 1 1 4 8 1 2 3 1 17 1 19 1 2 3 1 2 1 2 1 6 1 2 1 46 1 1 1 1 1 4 1 2 1 4 9 1 1 2 15 1 1 3 4 5 1 2 1 4 71 1 1 3 1 5 78 1 2 3 1 2 6 1 1 2 1 1 1 4 1 8 9 1 1 2 1 2 3 1 1 9 1 1 22 1 1 2 1 5 1 29 1 2 1 4 5 41 1 2 1 1 5 1 1 1 2 1 1 1 1 5 8 1 1 3 4 1 1 6...

output:

0
0
0
387445433
53260884
0
253952014
537163051
36559794
0
511384985
0
832504854
740181150
330078867
405525929
569684673
0
0
827053910
613985912
647990716
75829151
918618470
295766219
845315492
0
0
129206830
666746707
586695222
81186019
0
35517922
0
392622181
0
722722877
685721668
0
788434307
7688927...

result:

ok 100 numbers

Test #17:

score: 5
Accepted
time: 644ms
memory: 9812kb

input:

100 50000
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 10 1 1 1 1 1 1 5 1 22 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:

938322083
0
627807333
0
553973202
0
0
14048401
0
950421047
0
622576077
0
744029553
793127481
645301924
533609841
852154523
625396972
62789084
413008358
292040298
656049825
581436181
922659811
0
0
0
91815535
506836479
156002945
205212058
316354153
344645416
521003850
532634702
926445048
641763410
519...

result:

ok 100 numbers

Test #18:

score: 5
Accepted
time: 641ms
memory: 10852kb

input:

100 50000
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 4 1 6 1 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 9 1 32 1 1 1 1 2 1 1 1 1 1 1 1 1 1 3 1 1 65 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:

624885832
833309143
968068549
16720417
467661900
0
983405586
43591434
547668905
950286049
530347421
0
0
909087345
658815045
0
794306626
14976636
357941460
150818230
715847749
638450467
0
0
155568509
0
879137806
428155583
300267776
779360110
39013493
751776921
685994614
809532425
0
0
28163073
6789027...

result:

ok 100 numbers

Test #19:

score: 5
Accepted
time: 633ms
memory: 9692kb

input:

100 50000
1 1 2 3 1 5 1 1 1 3 5 1 2 14 15 1 2 1 1 2 1 1 1 3 4 1 10 11 14 15 1 2 3 1 20 1 2 3 1 1 2 4 1 2 10 1 1 3 4 1 2 1 4 5 1 7 1 2 10 1 1 1 1 2 1 2 6 1 1 3 1 5 1 1 8 15 1 2 34 1 1 1 2 1 1 2 3 1 2 7 1 1 2 4 1 1 97 1 99 1 1 1 1 2 6 7 1 1 1 1 3 5 6 1 1 2 11 1 2 1 15 1 1 124 1 1 1 2 5 1 2 8 9 1 1 1 3...

output:

475040820
821423600
161407909
880735181
500071559
337741049
134440032
894840892
976405119
528519244
473904119
936942481
875766540
93375618
980295619
621222155
0
393457466
0
0
281655372
418588257
269174342
31667135
0
0
462648500
0
528191112
831811998
548436806
0
0
917468062
373787292
425247061
235798...

result:

ok 100 numbers

Test #20:

score: 5
Accepted
time: 645ms
memory: 9840kb

input:

100 50000
1 1 1 1 1 3 1 1 6 1 1 1 10 1 12 1 1 1 4 1 2 1 4 1 2 3 1 1 2 3 5 1 18 1 2 3 1 1 1 1 1 2 1 2 1 10 1 2 1 1 1 16 1 2 3 23 1 2 3 1 5 1 2 1 1 5 6 1 2 3 1 11 1 1 1 4 1 2 1 2 3 1 5 1 9 1 11 1 1 1 3 1 2 79 1 1 2 3 4 1 1 1 2 5 1 2 3 1 5 15 17 1 1 1 1 1 1 2 5 1 27 1 29 1 2 1 2 3 1 7 8 1 2 3 1 133 1 2...

output:

0
0
682944657
750632782
263950446
693440161
405059290
525305126
44971279
123548737
0
741272096
576480062
0
677196555
0
145863649
0
0
0
987541820
0
714088381
470820324
0
893509858
0
0
258145392
0
374442624
393753011
495298252
455139328
0
454995497
462625493
552202545
35811919
51255305
465265116
94156...

result:

ok 100 numbers

Extra Test:

score: 0
Extra Test Passed