QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#716520#9586. 野兽节拍qzez#AC ✓40ms21412kbC++141.7kb2024-11-06 15:26:302024-11-06 15:26:31

Judging History

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

  • [2024-11-06 15:26:31]
  • 评测
  • 测评结果:AC
  • 用时:40ms
  • 内存:21412kb
  • [2024-11-06 15:26:30]
  • 提交

answer

#include<bits/stdc++.h>
#define fi first
#define se second
#define LB lower_bound
using namespace std;using ll=long long;using pii=pair<int,int>;
const int N=1e6+5;
int n;char s[N];
vector<int> S[26][26][26];
int pre[N],nxt[N];
int st[N],sh;
void del(int x){
	st[++sh]=x;
	pre[nxt[x]]=pre[x];
	nxt[pre[x]]=nxt[x];
}
void ins(int x){
	pre[nxt[x]]=nxt[pre[x]]=x;
}
int calc(int a,int b,int c){
	int p=1,pt=0;
	int cnt=0;
	while(p<=n){
		if(pre[pre[p]]>0&&s[pre[pre[p]]]==a&&s[pre[p]]==b&&s[p]==c){
			p=nxt[p];
			del(pre[pre[pre[p]]]);
			del(pre[pre[p]]);
			del(pre[p]);
			cnt++;
			continue;
		} 
		if(pre[p]>0&&nxt[p]<=n&&s[pre[p]]==a&&s[p]==b&&s[nxt[p]]==c){
			p=nxt[nxt[p]];
			del(pre[pre[pre[p]]]);
			del(pre[pre[p]]);
			del(pre[p]);
			cnt++;
			continue;
		}
		if(nxt[p]<=n&&nxt[nxt[p]]<=n&&s[p]==a&&s[nxt[p]]==b&&s[nxt[nxt[p]]]==c){
			p=nxt[nxt[nxt[p]]];
			del(pre[pre[pre[p]]]);
			del(pre[pre[p]]);
			del(pre[p]);
			cnt++;
			continue;
		}
		while(pt<S[a][b][c].size()&&S[a][b][c][pt]<p) pt++;
		if(pt==S[a][b][c].size()) break;
		p=S[a][b][c][pt]+3;
		del(p-3);del(p-2);del(p-1);
		cnt++;
	}
	while(sh) ins(st[sh]),sh--;
	return cnt;
}
void Solve(){
	scanf("%d%s",&n,s+1);
	for(int i=0;i<=n;i++) nxt[i]=i+1,pre[i+1]=i;
	for(int i=1;i<=n;i++) s[i]-='a';
	for(int i=2;i<n;i++) S[s[i-1]][s[i]][s[i+1]].push_back(i-1);
	int tot=0,a1,a2,a3;
	for(int x=0;x<26;x++) for(int y=0;y<26;y++) for(int z=0;z<26;z++){
		int w=calc(x,y,z);
		if(w>tot) tot=w,a1=x,a2=y,a3=z;
	}
	printf("%d\n%c%c%c",tot,a1+'a',a2+'a',a3+'a');
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 8508kb

input:

10
aaababbaab

output:

3
aab

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 2ms
memory: 10504kb

input:

14
liaoningdalian

output:

2
lia

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 1ms
memory: 10340kb

input:

3
zyl

output:

1
zyl

result:

ok 2 lines

Test #4:

score: 0
Accepted
time: 18ms
memory: 18960kb

input:

896376
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabababababababababababababababababaaaaaaaaaaaaaaaaaacacacacacacacacacacacacacacacacacaaaaaaaaaaaaaaaaaadadadadadadadadadadadadadadadadadaaaaaaaaaaaaaaaaaaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaaaaaaaaaaaaaaaaaafafafafafafafafafafa...

output:

3717
aaa

result:

ok 2 lines

Test #5:

score: 0
Accepted
time: 19ms
memory: 18832kb

input:

896376
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaababaaaaaaabababababaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaacacacacaaaaacacacacacacacaaacaaaaaaaaaaaaaaaaaadadaaaaaaaaadaaadadaaaaadaaaaadadaaaaaaaaaaaaaaaaaaaaaaeaeaaaaaeaaaaaaaeaeaeaaaaaaaeaaaaaaaaaaaaaaaaaaaafaaaaaaafafafafafa...

output:

7571
xxx

result:

ok 2 lines

Test #6:

score: 0
Accepted
time: 28ms
memory: 20008kb

input:

896376
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaababaaaaaaaaabaaabaaaaaaaaababaaaaaaaaaaaaaaaaaaaaaaaaaacaaaaacaaaaaaaaacacaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadaaaaaaaaaaaaaaaaaaaaadaaaaadaaaaaaaaaaaaaaaaaaaaeaeaeaaaaaeaaaaaeaaaaaeaeaaaeaeaaaaaaaaaaaaaaaaaafafaaafafaaaaaaaaaaa...

output:

6680
xxx

result:

ok 2 lines

Test #7:

score: 0
Accepted
time: 31ms
memory: 18952kb

input:

667888
eqjszvsxnlvgskosbdoyavaooutvfysniyfplykvmcnsgaomyeqqokqsrdykzfbzsbtkvotfsmmjgkhjhhxbgntmdzmxmexstdwwjrtsmumrrcvkeoluhcpvazdnoxscqibnyytrryywasediqzfsptsxggweogoxeoxhtxaynefaoscgobuxcprquxqzhircomstyufqkfdykbbuibknkjeyebhssdtqbxsdbqiwgseiaezqldbswtpdziicnnwvmxcozqttffglgefiwzdkbfnqmiuicjdcdodx...

output:

63
uzb

result:

ok 2 lines

Test #8:

score: 0
Accepted
time: 0ms
memory: 10144kb

input:

1000
baddacbabcddacdcbacaccbadddbadbdaddcdabbbcccdaaaddbadcdbddccadbbddcccaaadacdcbcbbccccabdbcbcdadacadcbcdbdbcddccddbbabdcabdabadddbbdacabdbbdddddaacdabdddddddbddbdcbadbcaaddccdbcbddaccdacbdaabbabababdcabdadddbacabcdbcddcdacaaddddbaccbbcbaacbcdcbbcdaacbaddcbcbcadaabacadadbaaababbccaddaccddbccdcbca...

output:

26
ddc

result:

ok 2 lines

Test #9:

score: 0
Accepted
time: 1ms
memory: 8480kb

input:

1000
ddcddcbbbcabbbbbccbaaddcbaaddcabbabbabdaacdcdbacbddabccddcadcaccadbaddcbcdccbddabccadadcdddbaaacdacadadddadacccbbddcacccccaccacccadbbacacbdccdbccdaabdabdabbddacdccdbaacdddcdbadabddbddbddbabcccdccbcddcdbbbcaaacbcdcdbdccabbdbcbadbbbbacddccadbbaddacaddcdbbbdcdbcbbdaaacadbccbabbbaacbcbaababbbabcdac...

output:

27
ddc

result:

ok 2 lines

Test #10:

score: 0
Accepted
time: 1ms
memory: 8560kb

input:

1000
bbccbcaaccbcdccaacbbcbadbabadddaabacadadacbbdacabdbdcaaaddabbabcacbddcdaccbcbcbddcabbbadacaaabcacbaabaccaccbdbbcddbddcadbbabaadcdccbbaacdbaddacaccbbabdacdbbbddccbcdbaccbbcddbbbddaaadccacdddddccbbbdcdadabbbcccbbbdddacbabacdccbdcdbdaacdabaaaccbbccdcddcdcdbcacacccdbabcaaadabbddcdbdbaacaaddcbcbbccb...

output:

24
bab

result:

ok 2 lines

Test #11:

score: 0
Accepted
time: 8ms
memory: 20104kb

input:

931528
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

310509
aaa

result:

ok 2 lines

Test #12:

score: 0
Accepted
time: 0ms
memory: 19184kb

input:

615161
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

205053
aaa

result:

ok 2 lines

Test #13:

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

input:

623944
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

200880
aaa

result:

ok 2 lines

Test #14:

score: 0
Accepted
time: 32ms
memory: 20768kb

input:

1000000
baabaabbaaaabbababbbabbbabaabbbaaaabaabbababbbbaabbaabbabbbbbbbaaaaabbbbbababaaababbbaababbbbbbaababbbaaabbbbbbbbababbbbabbbbabbbbbbbaabaaabbaaaaaaaaabbabababbabbbbaabbbbbaaabbbbabbbbaababbabaaaaaababbbaabbabbbbaaaabbbbaabbababaababbababbbbaaaabbbbabbaaabbbbaabaaaabbbbbaababaaabbbabaabababba...

output:

191420
aab

result:

ok 2 lines

Test #15:

score: 0
Accepted
time: 36ms
memory: 19460kb

input:

1000000
aabbbbbcbacccabaaaccccaacaccccbcaabacaaabacccabbcaccaaacbaabcbacbcaaababacbbacaabcbaaacbbaaaaaabbaaabbcbaabaccaacccacbbaabbaaaaaabbaccbcaabcabcacabcaacbacaccbbcbbbccbbbcaacbaabcacacccbcbacaccaaaccabaaccbbcbbbcbcabbcbabbabacbbbcbbbcacbcabbaaacbaaaccbacacabcccbbabaccaccbcbbccacbbabbbacacabaccc...

output:

40521
ccb

result:

ok 2 lines

Test #16:

score: 0
Accepted
time: 29ms
memory: 17736kb

input:

1000000
acdbcbcccdddcccdccadbdcccaaacbbdadbdacacaadcadadccdbbacdbcbddadabbdcbccbcadadbaddabdbadbbdcbcdcabbdabadabaaaddbcdbbaddcaadbcbcdacdbaacdbddbdacaaacadbbcadadacdbdcdcdccddbdddccacacbbcbbccacbdbbbdbcddbdcaccdcdcdbababbdbcbcacddddaadadcdcbbacbbdbddaadbbbbcccccabbadddbbbaaaddccdaadcaddbbdcdcdaabaa...

output:

16769
abd

result:

ok 2 lines

Test #17:

score: 0
Accepted
time: 35ms
memory: 17912kb

input:

1000000
abbaccdaecaaeadcaabecddbdedbcbebeeaeabaaaacedcaaabbbcabcbddcdcececcceacacaedeebaddabcdedeadbacabbbaadbeeeebbdaeadcacadadddbdbcaeeeaeddaccdceacebbaabccacdbdacdbcabaeeddeccecdcaeedbadbceebbcddbbeeecdeceabbdccccadcbeedacadceabadabcbcbbecddacbcbbbbbbadbacbdbcdbecadeecbeabceccabccdecccdbdcdbbeeee...

output:

8338
dce

result:

ok 2 lines

Test #18:

score: 0
Accepted
time: 36ms
memory: 20752kb

input:

1000000
abbbbbbabbababbbbaabababbbaaaaabbabbaaabababaaaababbbaaaabaababaaababbbaabbbbbbbaaaaabaabbabaabaaabaababaaabbabaaaaabbbbaabaababbbbbbbabaabaaabbabbbaaababaababababbbaababbaabbbbbaaabbaabbbbabbaabaababbaabbbabaaaabbababaabbabbabbabaabbbbaaababbbbbaaaabaaabbaabaaabaabbaabaaabaabaabbbaaaaabbbab...

output:

191383
bba

result:

ok 2 lines

Test #19:

score: 0
Accepted
time: 27ms
memory: 19108kb

input:

1000000
aabbcbcaabbabccabbbccabbcbacabccccccbbbcbccbabacacaccccbcbcbacaaaababbbabacacbbccaacbaacbacccabbabbbccbcbbbcbbacacaccbbaacbaaabaabbaccacccbcbbcacbbacabaabbabcacccaccbcacccccccbcbacaabbcbaaabaaabcabbaacabaaaaaccbabaabccbaabacbbcbbaabcbccccbcaccbbbccbbbbaabacbacbbaacbcccccbabacacbcccaaaccccaca...

output:

40925
caa

result:

ok 2 lines

Test #20:

score: 0
Accepted
time: 8ms
memory: 20504kb

input:

1000000
babbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabb...

output:

333333
abb

result:

ok 2 lines

Test #21:

score: 0
Accepted
time: 19ms
memory: 18492kb

input:

999986
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg...

output:

38461
abc

result:

ok 2 lines

Test #22:

score: 0
Accepted
time: 1ms
memory: 10540kb

input:

5388
xxyzyzaaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwabcabdabeabfabgabhabiabjabkablabmabnaboabpabqabrabsabtabuabvabwacdaceacfacgachaciacjackaclacmacnacoacpacqacracsactacuacvacwadeadfadgadhadiadjadkadladmadnadoadpadqadradsadtaduadvadwaefaegaehaeiaejaekaelaemaenaeoaepaeqaera...

output:

2
xyz

result:

ok 2 lines

Test #23:

score: 0
Accepted
time: 19ms
memory: 19568kb

input:

1000000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaacaacaacaacaacaacaacaacaacaacaacaacaacaacaacaacaacaacaadaadaadaadaadaadaadaadaadaadaadaadaadaadaadaadaadaadaaeaaeaaeaaeaaeaaeaaeaaeaaeaaeaaeaaeaaeaaeaaeaaeaaeaaeaafaaf...

output:

87
fwu

result:

ok 2 lines

Test #24:

score: 0
Accepted
time: 1ms
memory: 8468kb

input:

6
ababaa

output:

1
aba

result:

ok 2 lines

Test #25:

score: 0
Accepted
time: 1ms
memory: 8448kb

input:

6
aababa

output:

2
aba

result:

ok 2 lines

Test #26:

score: 0
Accepted
time: 30ms
memory: 20560kb

input:

1000000
zenudggmyopddhszhrbmftgzmjorabhgojdtfnzxjkayjlkgczsyshczutkdchiytqlfsevymipufxkxojlvkkqxvjhpjmcxeiluubblcdiwjphlpzwvknsyvbcodpyktizgatrlieiikktghixbikehsiknjuateltwkyyhgabygwtclyeyquaoiqnypoxnvyzvyhfejoljxnwhkkcgitdebuutnzzvawollaiesjsnlbdvdarlewlnusmgwhulzimadkzlngoukodeljdpjpxxdljooczhewfz...

output:

90
cze

result:

ok 2 lines

Test #27:

score: 0
Accepted
time: 39ms
memory: 20184kb

input:

1000000
rtzxovxqfapkdmelxiyjroohufhbakpmmvaxqcptiwtcijcabvobzwbrespqhpvjidgmlvjetwieqngdfbinbsjyfgxofbunxgmhjnkdhhwzjaqqhxjurewcpktfzgxdheuuyfrcmqxykcxjaeotsutxkedqsoyoxzvcspgbnzrwypgdqnfbxywblqvdufggbbskburngiyxtrauvhxjeposnzhcbxlkcczhvpxdbmegacemorezpcsnlzbbiasssvhgneavpnoeikfrhkxeredmmsuowksdtoon...

output:

88
yqs

result:

ok 2 lines

Test #28:

score: 0
Accepted
time: 40ms
memory: 21412kb

input:

1000000
ljmybiqxmnqqbsoxkyvgdiupdyamxtyvhjvbdsgogfkgghvubrlefmxiorufmakswraubnxjakandedlvsfepzcxnelmzqkeqbqrawwukmicllbvauvtzuajjsmxuuuzvypgzstvpbmpktcluzglzelpaayvyhwkqmzixfotvxjsohrctbgdezsorqehyxozheoxcgcwcellqwdhgdqjxkyiaetlntxbfgkehdlfkoococgfziqkcibndisxwwsanicoxybhrtpphfibclqqbtmaxbendpnagfxb...

output:

87
qfh

result:

ok 2 lines

Test #29:

score: 0
Accepted
time: 31ms
memory: 19700kb

input:

1000000
fyyymvhdtbqyaxbiypqdqdaykusyvdgccwsfohwjgrckffnqanhhkaubwqzsrjzcleuatejofztxpvaqmidwghvywbbltfcujzrerfgjoowflukcusivimfoedcoqlstisjtzfvmtnbhllflpuyfhoagswuyfbufmzbncwvocvzngafbvnkfkbrcutmldoxqnikmdtodzzzzmchstallsfjwmjhszqiqhmwcrsaftrzvebgwhydynoiotqhqkrqhgxxufscrvapaebmmxljfiiuoiiomnxhwwxgp...

output:

92
nsk

result:

ok 2 lines

Test #30:

score: 0
Accepted
time: 34ms
memory: 20072kb

input:

1000000
zokbxiahaosfyclumgnaczggrnljumplxknibxmeedvnefhkygdkqosshpegwunnzsohmxxumnnhckwyczaowpoxezqlovukcuuqgrsbrtifngthlquuqdjvyltgjbrmwoefypvdyzqwlainjoqxrzrwktnblvszfndrjodikurlytsayblhpdnrytxnhfejtjfzeeamttmnjgkffwelozvmyosbmoufjpjzbeohbulotcinspqmyurolxwlwloobkszpnddxhrkbxoytmdsqxaetqzmufcslqpd...

output:

89
ynq

result:

ok 2 lines

Extra Test:

score: 0
Extra Test Passed