UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#197334#2815. 电线工tkswls1002475ms9936kbC++111.1kb2023-11-11 11:33:122023-11-11 12:12:12

answer

#include<bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long f[1000006], n, m, l;
bool b[1000006];
vector<long long> v;
void calc() {
	f[n] += f[1];
	for (int i = 1, k = 0; i <= n; i++) {
		if (i > l && b[i - l]) {
			f[i] += f[i - l];
			f[i] %= mod;
		}
		if (i < n) {
			f[i + 1] += f[i];
			f[i + 1] %= mod;
		}
		while (k < m && i - v[k] >= l) k++;
		if (b[i]) {
			for (int j = k; j < m && v[j] < i; j++) {
				long long op = v[j];
				f[i] += f[op];
				f[i] %= mod;
				f[op] = f[i];
			}
		}
	}
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m >> l;
	long long p;
	for (int i = 1; i <= m; i++) {
		cin >> p;
		b[p] = true;
		v.push_back(p);
	}
	long long ans1, ans2, ans3, ans4, ans;
	sort(v.begin(), v.end());
	f[1] = 1;
	calc();
	ans1 = f[n];
	ans3 = f[n - 1];
	memset(f, 0, sizeof(f));
	f[2] = 1;
	calc();
	ans2 = f[n - 1];
	ans4 = f[n];
	ans4 *= ans3;
	ans4 %= mod;
	ans2 *= ans1;
	ans2 %= mod;
	ans = ans2 - ans4;
	if (ans < 0) ans += mod;
	cout << ans;
	return 0;
}

Details

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

Test #1:

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

input:

10 7 2
1 3 4 5 6 7 8

output:

144

result:

ok single line: '144'

Test #2:

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

input:

10 7 3
1 2 3 4 5 6 7

output:

729

result:

ok single line: '729'

Test #3:

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

input:

10 4 2
1 2 5 8

output:

6

result:

ok single line: '6'

Test #4:

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

input:

10 6 3
1 2 4 5 6 7

output:

126

result:

ok single line: '126'

Test #5:

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

input:

10 7 2
1 2 3 4 5 6 8

output:

144

result:

ok single line: '144'

Test #6:

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

input:

10 6 4
1 2 3 4 5 6

output:

550

result:

ok single line: '550'

Test #7:

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

input:

1000 481 312
1 2 3 5 6 7 9 10 11 12 13 14 15 16 17 20 22 23 24 26 27 28 29 31 34 35 36 40 41 42 43 4...

output:

821844711

result:

ok single line: '821844711'

Test #8:

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

input:

1000 302 403
1 4 6 10 11 14 16 17 18 19 22 24 26 28 30 31 32 34 35 36 38 39 41 42 45 46 47 53 56 57 ...

output:

357144982

result:

ok single line: '357144982'

Test #9:

score: 5
Accepted
time: 5ms
memory: 9096kb

input:

1000 649 243
1 2 3 4 5 6 7 8 10 11 12 13 15 16 17 18 19 20 21 22 23 27 28 29 30 31 32 33 34 36 38 39...

output:

506565207

result:

ok single line: '506565207'

Test #10:

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

input:

1000 595 372
1 3 4 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 3...

output:

890245463

result:

ok single line: '890245463'

Test #11:

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

input:

1000 668 248
1 2 5 6 8 9 10 11 12 13 14 16 17 18 19 21 22 23 24 25 26 28 29 30 31 32 33 34 35 37 38 ...

output:

963223651

result:

ok single line: '963223651'

Test #12:

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

input:

1000 331 405
1 2 3 7 9 10 12 13 14 15 17 18 20 21 22 23 24 27 28 30 31 32 33 34 36 37 38 41 50 52 55...

output:

899040706

result:

ok single line: '899040706'

Test #13:

score: 5
Accepted
time: 265ms
memory: 9848kb

input:

1000000 7404 343304
1 14 143 166 173 190 644 651 676 889 955 1094 1098 1139 1363 1450 1500 1562 1565...

output:

903710079

result:

ok single line: '903710079'

Test #14:

score: 5
Accepted
time: 319ms
memory: 9804kb

input:

1000000 7697 394385
1 89 106 153 164 193 292 294 348 354 374 450 506 534 664 826 859 916 996 1029 10...

output:

811456965

result:

ok single line: '811456965'

Test #15:

score: 5
Accepted
time: 232ms
memory: 9732kb

input:

1000000 6167 455393
1 150 208 292 414 570 626 634 656 680 691 822 1015 1100 1183 1257 1337 1392 1498...

output:

169947983

result:

ok single line: '169947983'

Test #16:

score: 5
Accepted
time: 464ms
memory: 9764kb

input:

1000000 8946 442025
1 7 112 172 529 572 645 681 737 912 1000 1031 1039 1071 1165 1171 1173 1202 1229...

output:

8783643

result:

ok single line: '8783643'

Test #17:

score: 5
Accepted
time: 466ms
memory: 9720kb

input:

1000000 8832 480934
1 2 47 75 130 218 254 325 353 475 507 519 526 679 745 818 822 848 898 904 986 10...

output:

629608576

result:

ok single line: '629608576'

Test #18:

score: 5
Accepted
time: 277ms
memory: 9936kb

input:

1000000 8814 261150
1 11 30 46 91 128 130 140 147 258 298 318 410 464 516 523 575 638 829 914 960 97...

output:

84632445

result:

ok single line: '84632445'

Test #19:

score: 5
Accepted
time: 187ms
memory: 9904kb

input:

1000000 6961 284171
1 238 319 442 541 647 705 733 753 836 1021 1172 1173 1216 1278 1396 1400 1514 17...

output:

190050433

result:

ok single line: '190050433'

Test #20:

score: 5
Accepted
time: 252ms
memory: 9716kb

input:

1000000 6369 468537
1 30 39 61 163 211 256 275 355 475 577 635 772 884 899 932 950 955 1021 1097 121...

output:

889690729

result:

ok single line: '889690729'