QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#702199#7814. 消消乐zdrj100 ✓43ms18640kbC++14499b2024-11-02 15:28:412024-11-02 15:28:42

Judging History

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

  • [2024-11-02 15:28:42]
  • 评测
  • 测评结果:100
  • 用时:43ms
  • 内存:18640kb
  • [2024-11-02 15:28:41]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
const int N=2e6+5;
int n;
ll ans;
char s[N];
int st[N],tot;
ull hs[N];
unordered_map<ull,int>mp;
int main() {
	scanf("%d%s",&n,s+1);
	mp[0]=1;
	for(int i=1;i<=n;i++) {
		if(tot&&s[st[tot]]==s[i]) --tot;
		else st[++tot]=i;
		if(tot) hs[tot]=hs[tot-1]*137+s[st[tot]];
		++mp[hs[tot]];
	}
	for(auto t:mp) {
		ans+=1ll*t.second*(t.second-1)/2;
	}
	printf("%lld",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: 5852kb

input:

10
aaaaaaaaaa

output:

25

result:

ok single line: '25'

Test #2:

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

input:

10
ooooppuuhh

output:

16

result:

ok single line: '16'

Test #3:

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

input:

10
nnppkkppjj

output:

16

result:

ok single line: '16'

Test #4:

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

input:

10
vvcckkhhqq

output:

15

result:

ok single line: '15'

Test #5:

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

input:

10
llmmxxoopp

output:

15

result:

ok single line: '15'

Test #6:

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

input:

800
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjddzziiyyyyjjooppiivvppmmooppttnnbbmmaaqqvvkkllyyvvmmjjsswwxxccwweeeekkhhaakkvvffaaiieessmmiibbff...

output:

38306

result:

ok single line: '38306'

Test #7:

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

input:

800
pffpgppguqqugllgwhhwxjjxpkkpxnnxlkklunnuxiixallayqqyccccjnnjnyynqccqqjjqtuutboobwddwfwwfgvvgwuuwpqqppttpyggysrrsgwwgeddexbbxbssbvbbvbeebweewwkkwwddwnoontddtcddcajjapffptcctkeekboobfjjfvaavpjjpriirlfflnazdsevmozgezlngnhktrllcgorjoollwtqylmmzxfeibnifcebsnnugzluzlizievzxfnlokzodymigextlmyltzbmptyjf...

output:

27479

result:

ok single line: '27479'

Test #8:

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

input:

8000
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv...

output:

3820477

result:

ok single line: '3820477'

Test #9:

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

input:

8000
neenbnnbvjjvddddommolrrlzttzqwwqlfflijjiaqqayaayihhiqmmqduudlzzlyzzyannatyytfiifbqqbroorcffcgjjgwhhwoqqopuupdjjdeqqewnnwvwwvpiiprqqrukkuhbbhsiisrqqrxvvxfmmfzkkzjlljimmiazzariirdvvdcuucpaapbaabbaabccccxqqxivvipttpqffqmggmzhhzdaadyxxyhccheddeaiianggnxjjxqssqfaafqllqskksfuufviivozzocwwcznnzfxxfnss...

output:

2713693

result:

ok single line: '2713693'

Test #10:

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

input:

8000
ivviurrukrrkaccafoofaxxaleelcyycsiisimmifvvfoeeodppdneenqjjqsccsguugonnoyiiymttmcjjcmkkmjwwjieeikeekdbbdolloyvvyolloxiixmaamfnnfzrrzqbbqweewvttvboobbeebcmmcsqqsiyyifddfyvvyvttvvddvejjeeeeeleellzzlzbbzcrrcobbowsswquuqozzoyqqyulluwvvwyxxyxllxwrrwgmmgeppecvvcsiisyvvyukkuyppyryyrhjjhthhtvssvvnnvnee...

output:

2721590

result:

ok single line: '2721590'

Test #11:

score: 5
Accepted
time: 29ms
memory: 18640kb

input:

200000
tdaatgfvypbdkxdlvttiuksoooxszoqnqvmtznizlqfstlenqrnmdpkmvhmzftporwzvlbpyplrvrkgrpvqxyjcwwpcinilarbaudodadcglszflkzvmmdahgqphqoueltddqlymwpvweslymviccsmhuezesmlwsswgznaofullpxciuezrbkxfnodiglhpyrfcjajyuqzfoxsysgeqrqmvtqysypgaivfetwhmgxngzdvavbkipanoopqftdmntwpxgaljiqrkppywfuspzfgljheckapftjqar...

output:

8356

result:

ok single line: '8356'

Test #12:

score: 5
Accepted
time: 29ms
memory: 18048kb

input:

200000
nleqrvpkpopfbstnolidsxrfhivbwbbqbwxmvymzmnwozrbklbuwliccquzhpfjsbxlnkzewvjpjarqmwcpsvovxeynjrgdjxrauincbnjvokawliinjqqulwxxeztpbrotihuiyjjqsxxosragocxbpjmhquczgwfakfaojxslteazikjqkebpcrrggswjiyetkpyvjubhtoounhveftykvetuwqgpddicnarbsigpjytmhcymvapbmkforkaeccsuhmwiuljmvajlztzjghnohlmxnmdehfxnra...

output:

8340

result:

ok single line: '8340'

Test #13:

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

input:

200000
abbabbbbbbaababaaabaaaababaaaaaabbababababbabbaaababbbbaabaabbbbbbababaabababbababaabbaabaaaabbbbbaabbbbaababbbabaaababbbbbbbbbbabbbabaabaabaababbbbbbabaabbbbbbbbbbaaabbbbabaabbaababaaabbabbaaabbbbbaaabababaababbaaabbbbababbbbbbaaaabaaaaaaabbbaabbaaaabbabbbbbaabbbbbbbabbaaaabaaabaabbaaaababbb...

output:

52315097

result:

ok single line: '52315097'

Test #14:

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

input:

200000
aaaababaaaaabbabababbbbabbbbababbabbaabaaabbabbaabaaaaaabaaaabbbbbbbabaabbabaabababbbaabbbbabbbbbaabaaaabaaaababaaaabbaaaaabbbabbbabbbbbbbaabbbabbaaabbbabaabaaaaaaaaababbaaabbbbaabaabbaaababbabbaabbbbaaababbbbbbbbbbbaabaaabbaaabaabbaaabbabaabbabbaabbbababbaaabaaaaaabbbbbbbabaabbabbaabaabaabaa...

output:

72221142

result:

ok single line: '72221142'

Test #15:

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

input:

200000
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy...

output:

2395581278

result:

ok single line: '2395581278'

Test #16:

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

input:

200000
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

2396621459

result:

ok single line: '2396621459'

Test #17:

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

input:

200000
ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo...

output:

2395864064

result:

ok single line: '2395864064'

Test #18:

score: 5
Accepted
time: 40ms
memory: 16704kb

input:

2000000
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii...

output:

239586659381

result:

ok single line: '239586659381'

Test #19:

score: 5
Accepted
time: 40ms
memory: 16092kb

input:

2000000
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

output:

239687303822

result:

ok single line: '239687303822'

Test #20:

score: 5
Accepted
time: 43ms
memory: 16432kb

input:

2000000
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv...

output:

239608981171

result:

ok single line: '239608981171'