UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#212633#3837. 子串调整drdilyor50902ms1200kbC++747b2024-10-19 17:28:422024-10-19 18:36:43

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
void ts(){cout<<"IAKIOI\n";}
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 n,k;
int a[1000005];
const int mod=998244353;
signed main(){
	n=read(),k=read();
	for(int i=1;i<=n;i++)a[i]=read();
	int res=0;
	for(int i=1;i<=n;i++){
		int cur=0;
		int lst=0;
		for(int j=i;j<=n;j++){
			int to=(k-lst)%k;
			cur+=min(to,(k-to)%k);cur%=mod;
			lst=a[j]-to+k;lst%=k;
			if(!lst)res+=cur,res%=mod;
			else res-=1,res+=mod,res%=mod;
		}
	}
	cout<<res<<"\n";
	return 0;
}
//look at my code
//my code is amazing

Details

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

Test #1:

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

input:

10 7
1 6 1 3 4 0 0 0 0 6

output:

25

result:

ok 1 number(s): "25"

Test #2:

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

input:

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

output:

7

result:

ok 1 number(s): "7"

Test #3:

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

input:

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

output:

998244351

result:

ok 1 number(s): "998244351"

Test #4:

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

input:

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

output:

0

result:

ok 1 number(s): "0"

Test #5:

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

input:

100 77
3 5 72 64 11 46 33 27 50 31 43 35 43 55 24 58 19 50 24 58 21 9 68 37 39 16 63 32 43 32 47 62 ...

output:

154351

result:

ok 1 number(s): "154351"

Test #6:

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

input:

100 80
2 68 11 26 53 66 16 40 39 40 39 32 48 68 14 66 12 79 2 22 59 66 13 17 64 44 34 32 50 77 3 47 ...

output:

161567

result:

ok 1 number(s): "161567"

Test #7:

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

input:

100 74
3 3 71 12 61 25 47 24 50 27 49 73 0 16 57 13 61 64 11 0 73 28 46 22 53 61 14 9 64 40 36 41 31...

output:

127593

result:

ok 1 number(s): "127593"

Test #8:

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

input:

100 71
2 70 1 33 38 11 61 41 27 67 7 41 30 51 20 0 70 19 53 18 52 58 13 7 65 45 26 39 30 44 27 70 1 ...

output:

130545

result:

ok 1 number(s): "130545"

Test #9:

score: 5
Accepted
time: 447ms
memory: 1196kb

input:

5000 594292
2 252917 341380 487382 106911 469814 124474 344327 249963 46836 547454 153656 440638 575...

output:

316110309

result:

ok 1 number(s): "316110309"

Test #10:

score: 5
Accepted
time: 455ms
memory: 1200kb

input:

5000 988526
0 308382 680150 695952 292572 417837 570687 25939 962587 86047 902484 662966 325556 5509...

output:

737806736

result:

ok 1 number(s): "737806736"

Test #11:

score: 0
Time Limit Exceeded

input:

100000 80795578
1 37947564 42848013 22409073 58386505 18651679 62143900 69336355 11459222 31046525 4...

output:


result:


Test #12:

score: 0
Time Limit Exceeded

input:

100000 64086438
0 40835786 23250652 62315010 1771428 49444220 14642218 34723179 29363260 39459342 24...

output:


result:


Test #13:

score: 0
Time Limit Exceeded

input:

1000000 29
0 26 5 4 26 26 5 2 28 3 25 22 7 27 28 8 20 23 14 14 15 18 8 1 26 18 11 27 4 2 25 19 10 23...

output:


result:


Test #14:

score: 0
Time Limit Exceeded

input:

1000000 30
4 6 22 6 25 23 12 24 7 10 19 29 2 9 15 16 19 21 5 10 19 22 8 26 7 6 20 24 12 21 10 15 7 1...

output:


result:


Test #15:

score: 0
Time Limit Exceeded

input:

1000000 80659851
29706357 69181753 51163169 63290196 43732766 34561951 17460761 42492172 1854204 411...

output:


result:


Test #16:

score: 0
Time Limit Exceeded

input:

1000000 94987149
92484609 16896672 67414227 48153213 28104363 189294 44655282 7852175 13546629 39665...

output:


result:


Test #17:

score: 0
Time Limit Exceeded

input:

1000000 95016981
5 32913643 62103339 31683000 63333981 74739024 20277955 87278897 7738082 40993909 5...

output:


result:


Test #18:

score: 0
Time Limit Exceeded

input:

1000000 73023937
7 18300579 54723352 18623660 54400283 12861737 60162193 25662581 47361363 63739597 ...

output:


result:


Test #19:

score: 0
Time Limit Exceeded

input:

1000000 50446785
0 49342522 1104263 34961758 15485027 25882243 24564542 6960583 43486203 36140724 14...

output:


result:


Test #20:

score: 0
Time Limit Exceeded

input:

1000000 80058081
0 30191959 49866123 15675035 64383046 30113402 49944678 47265345 32792736 37424895 ...

output:


result: