QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#536354#7814. 消消乐mingjunyi100 ✓23ms147820kbC++20873b2024-08-29 07:11:172024-08-29 07:11:18

Judging History

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

  • [2024-08-29 07:11:18]
  • 评测
  • 测评结果:100
  • 用时:23ms
  • 内存:147820kb
  • [2024-08-29 07:11:17]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long	
int rd() {
	int x = 0, w = 1;
	char ch = 0;
	while (ch < '0' || ch > '9') {
		if (ch == '-') w = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		x = x * 10 + (ch - '0');
		ch = getchar();
	}
	return x * w;
}

void wt(int x) {
	static int sta[35];
	int f = 1;
	if(x < 0) f = -1,x *= f;
	int top = 0;
	do {
		sta[top++] = x % 10, x /= 10;
	} while (x);
	if(f == -1) putchar('-');
	while (top) putchar(sta[--top] + 48);
}
const int N = 2e6 + 5;
int n;
char s[N];
int dp[N],to[N],f[N][26],ans;

signed main() {
	scanf("%lld",&n);
	scanf("%s",s + 1);
	for(int i = 1;i<=n;i++) {
		to[i] = i;
		int x;
		x = f[to[i - 1]][s[i] - 'a'];
		if(x) to[i] = to[x - 1],dp[i] = dp[x - 1] + 1;
		f[to[i]][s[i] - 'a'] = i;
		ans += dp[i]; 
	}
	wt(ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

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

input:

10
aaaaaaaaaa

output:

25

result:

ok single line: '25'

Test #2:

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

input:

10
ooooppuuhh

output:

16

result:

ok single line: '16'

Test #3:

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

input:

10
nnppkkppjj

output:

16

result:

ok single line: '16'

Test #4:

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

input:

10
vvcckkhhqq

output:

15

result:

ok single line: '15'

Test #5:

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

input:

10
llmmxxoopp

output:

15

result:

ok single line: '15'

Test #6:

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

input:

800
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjddzziiyyyyjjooppiivvppmmooppttnnbbmmaaqqvvkkllyyvvmmjjsswwxxccwweeeekkhhaakkvvffaaiieessmmiibbff...

output:

38306

result:

ok single line: '38306'

Test #7:

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

input:

800
pffpgppguqqugllgwhhwxjjxpkkpxnnxlkklunnuxiixallayqqyccccjnnjnyynqccqqjjqtuutboobwddwfwwfgvvgwuuwpqqppttpyggysrrsgwwgeddexbbxbssbvbbvbeebweewwkkwwddwnoontddtcddcajjapffptcctkeekboobfjjfvaavpjjpriirlfflnazdsevmozgezlngnhktrllcgorjoollwtqylmmzxfeibnifcebsnnugzluzlizievzxfnlokzodymigextlmyltzbmptyjf...

output:

27479

result:

ok single line: '27479'

Test #8:

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

input:

8000
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv...

output:

3820477

result:

ok single line: '3820477'

Test #9:

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

input:

8000
neenbnnbvjjvddddommolrrlzttzqwwqlfflijjiaqqayaayihhiqmmqduudlzzlyzzyannatyytfiifbqqbroorcffcgjjgwhhwoqqopuupdjjdeqqewnnwvwwvpiiprqqrukkuhbbhsiisrqqrxvvxfmmfzkkzjlljimmiazzariirdvvdcuucpaapbaabbaabccccxqqxivvipttpqffqmggmzhhzdaadyxxyhccheddeaiianggnxjjxqssqfaafqllqskksfuufviivozzocwwcznnzfxxfnss...

output:

2713693

result:

ok single line: '2713693'

Test #10:

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

input:

8000
ivviurrukrrkaccafoofaxxaleelcyycsiisimmifvvfoeeodppdneenqjjqsccsguugonnoyiiymttmcjjcmkkmjwwjieeikeekdbbdolloyvvyolloxiixmaamfnnfzrrzqbbqweewvttvboobbeebcmmcsqqsiyyifddfyvvyvttvvddvejjeeeeeleellzzlzbbzcrrcobbowsswquuqozzoyqqyulluwvvwyxxyxllxwrrwgmmgeppecvvcsiisyvvyukkuyppyryyrhjjhthhtvssvvnnvnee...

output:

2721590

result:

ok single line: '2721590'

Test #11:

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

input:

200000
tdaatgfvypbdkxdlvttiuksoooxszoqnqvmtznizlqfstlenqrnmdpkmvhmzftporwzvlbpyplrvrkgrpvqxyjcwwpcinilarbaudodadcglszflkzvmmdahgqphqoueltddqlymwpvweslymviccsmhuezesmlwsswgznaofullpxciuezrbkxfnodiglhpyrfcjajyuqzfoxsysgeqrqmvtqysypgaivfetwhmgxngzdvavbkipanoopqftdmntwpxgaljiqrkppywfuspzfgljheckapftjqar...

output:

8356

result:

ok single line: '8356'

Test #12:

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

input:

200000
nleqrvpkpopfbstnolidsxrfhivbwbbqbwxmvymzmnwozrbklbuwliccquzhpfjsbxlnkzewvjpjarqmwcpsvovxeynjrgdjxrauincbnjvokawliinjqqulwxxeztpbrotihuiyjjqsxxosragocxbpjmhquczgwfakfaojxslteazikjqkebpcrrggswjiyetkpyvjubhtoounhveftykvetuwqgpddicnarbsigpjytmhcymvapbmkforkaeccsuhmwiuljmvajlztzjghnohlmxnmdehfxnra...

output:

8340

result:

ok single line: '8340'

Test #13:

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

input:

200000
abbabbbbbbaababaaabaaaababaaaaaabbababababbabbaaababbbbaabaabbbbbbababaabababbababaabbaabaaaabbbbbaabbbbaababbbabaaababbbbbbbbbbabbbabaabaabaababbbbbbabaabbbbbbbbbbaaabbbbabaabbaababaaabbabbaaabbbbbaaabababaababbaaabbbbababbbbbbaaaabaaaaaaabbbaabbaaaabbabbbbbaabbbbbbbabbaaaabaaabaabbaaaababbb...

output:

52315097

result:

ok single line: '52315097'

Test #14:

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

input:

200000
aaaababaaaaabbabababbbbabbbbababbabbaabaaabbabbaabaaaaaabaaaabbbbbbbabaabbabaabababbbaabbbbabbbbbaabaaaabaaaababaaaabbaaaaabbbabbbabbbbbbbaabbbabbaaabbbabaabaaaaaaaaababbaaabbbbaabaabbaaababbabbaabbbbaaababbbbbbbbbbbaabaaabbaaabaabbaaabbabaabbabbaabbbababbaaabaaaaaabbbbbbbabaabbabbaabaabaabaa...

output:

72221142

result:

ok single line: '72221142'

Test #15:

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

input:

200000
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy...

output:

2395581278

result:

ok single line: '2395581278'

Test #16:

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

input:

200000
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

2396621459

result:

ok single line: '2396621459'

Test #17:

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

input:

200000
ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo...

output:

2395864064

result:

ok single line: '2395864064'

Test #18:

score: 5
Accepted
time: 16ms
memory: 144140kb

input:

2000000
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii...

output:

239586659381

result:

ok single line: '239586659381'

Test #19:

score: 5
Accepted
time: 23ms
memory: 147820kb

input:

2000000
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

output:

239687303822

result:

ok single line: '239687303822'

Test #20:

score: 5
Accepted
time: 15ms
memory: 145284kb

input:

2000000
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv...

output:

239608981171

result:

ok single line: '239608981171'