UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#211133#3799. 猫哭drdilyor52581ms2424kbC++112.3kb2024-08-09 12:06:582024-08-09 12:55:18

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;
}
const int mod=998244353;
struct mint{
    int x;mint(int o=0){x=o;}mint&operator+=(mint a){return(x+=a.x)%=mod,*this;}mint&operator-=(mint a){return(x+=mod-a.x)%=mod,*this;}
    mint&operator*=(mint a){return(x=1ll*x*a.x%mod),*this;}mint&operator^=( int b){mint a=*this;x=1;while(b)(b&1)&&(*this*=a,1),a*=a,b>>=1;return*this;}
    mint&operator/=(mint a){return*this*=(a^=mod-2);}friend mint operator+(mint a,mint b){return a+=b;}friend mint operator-(mint a,mint b){return a-=b;}
    friend mint operator*(mint a,mint b){return a*=b;}friend mint operator/(mint a,mint b){return a/=b;}friend mint operator^(mint a,int b){return a^=b;}
    mint operator-(){return 0-*this;}bool operator==(const mint b)const{return x==b.x;}
};
char s[1000005];
int dp[55][55][55];
//有多少 TA, 有多少个 T.
void solve(){
	scanf("%s",s+1);
	int n=0;
	int l=strlen(s+1);
	for(int i=1;i<=l;i++){
		if(s[i]=='C'||s[i]=='A'||s[i]=='T')s[++n]=s[i];
	}
	reverse(s+1,s+n+1);
	if(n<=50){
		for(int i=0;i<=n;i++){
			for(int j=0;j<=n;j++)for(int k=0;k<=n;k++)dp[i][j][k]=-(1ll<<60);
		}
		dp[0][0][0]=0;
		for(int i=1;i<=n;i++){
			for(int j=0;j<=n;j++){
				for(int k=0;k<=n;k++){
					if(dp[i-1][j][k]<0)continue;
					dp[i][j][k]=max(dp[i][j][k],dp[i-1][j][k]);
					if(s[i]=='A'){
						if(k)dp[i][j+1][k-1]=max(dp[i][j+1][k-1],dp[i-1][j][k]);
					}
					else if(s[i]=='T'){
						dp[i][j][k+1]=max(dp[i][j][k+1],dp[i-1][j][k]);
						if(j)dp[i][j-1][k]=max(dp[i][j-1][k],dp[i-1][j][k]+1);
					}
					else{
						if(j)dp[i][j-1][k]=max(dp[i][j-1][k],dp[i-1][j][k]+1);
					}
				}
			}
		}
		int res=0;
		for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)res=max(res,dp[n][i][j]);
		printf("%lld\n",res);return;
	}
	int cnt=0;
	int ta=0,t=0;
	for(int i=1;i<=n;i++){
		if(s[i]=='T'){
			if(ta){cnt++,ta--;}
			else t++;
		}
		else if(s[i]=='A'){
			if(t){ta++,t--;}
		}
		else{
			if(ta){cnt++,ta--;}
		}
	}
	cout<<cnt<<"\n";
}
signed main(){
	int t=read();
	while(t--)solve();
	return 0;
}

详细

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

Test #1:

score: 4
Accepted
time: 0ms
memory: 1240kb

input:

40
CCCATGCA
CCTATCAT
GTCTGCTA
ACACCTCC
TTATAACA
ATGATCAT
TATTACCA
CAAGCACC
CTCTCCTC
CTTTAAAT
CACTTCC...

output:

1
2
0
1
1
2
1
0
0
1
1
1
1
1
1
1
1
1
2
1
0
1
1
0
0
0
1
1
1
1
2
1
0
1
1
1
1
1
1
0

result:

ok 40 tokens

Test #2:

score: 4
Accepted
time: 1ms
memory: 1220kb

input:

40
GTACT
CATCT
ATAAT
TCAGT
ATTCG
ACTTT
TCCGA
CACTA
TGATC
TGTCA
AATAT
AACCT
TATCT
TCCTC
ATATG
AGTCA
C...

output:

1
1
1
1
0
0
0
1
1
0
1
0
1
0
1
0
1
1
0
0
0
0
0
0
0
1
0
0
1
1
0
1
0
0
1
1
1
1
0
1

result:

ok 40 tokens

Test #3:

score: 4
Accepted
time: 0ms
memory: 1344kb

input:

40
GCATTCTACCAGAGT
TGGGTATAAATTTCT
AAACCCTGTTTTTAC
TCCCATCTCAATCTG
CATCGCTTTAAACTT
TACACGATTCATCAC
T...

output:

2
3
0
3
3
3
2
2
2
1
3
2
3
2
2
2
3
3
2
1
4
2
3
1
1
1
2
2
3
2
2
1
2
3
2
2
2
2
2
2

result:

ok 40 tokens

Test #4:

score: 4
Accepted
time: 0ms
memory: 1344kb

input:

40
TAGACACTATCTTCC
CCTATCCCATACAAT
AGTCTTACCGCTCCA
AGCTCAAATAAATCA
GAACACCCCAAACAA
ATACCAACTCATCAA
C...

output:

3
3
1
2
0
2
4
4
2
1
3
2
0
3
1
3
2
1
4
2
2
2
2
2
3
2
3
2
2
1
3
2
3
2
3
2
1
1
2
0

result:

ok 40 tokens

Test #5:

score: 4
Accepted
time: 0ms
memory: 1208kb

input:

40
EJUPFQZTAJCKRQD
UMDIIZLTKGXGUUY
RNFTZBNKAYNSWZT
KEGHKRLQWKXJFSI
XZLUPCKNWHVBDZO
LYBUUCYFIUGEECF
Z...

output:

0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 40 tokens

Test #6:

score: 4
Accepted
time: 2ms
memory: 2380kb

input:

10
TAATTCCTACCTCTATAATAATACCCCACCCTACATCAATCGAATTTCAA
CACATAAATCCCCATCTAGTTCAGCTTTTTCTATAAACATAATATC...

output:

11
12
6
9
9
13
8
10
11
7

result:

ok 10 tokens

Test #7:

score: 4
Accepted
time: 3ms
memory: 2356kb

input:

10
ATATATCTGCTAGTCTTCGCCGCTACATAACGCTACTACGAATTGCAACC
TGATATCCTTCCCTTAGTTTATCATTGATATTATCACACAAAAATT...

output:

8
12
12
11
10
11
13
10
10
12

result:

ok 10 tokens

Test #8:

score: 4
Accepted
time: 0ms
memory: 2356kb

input:

10
CGACGCCCTAACAAGCACGAACCTTTTTGCAACAGATATTCACAAATATG
TTATACCTTCACACTTTACTACATACAGCACTCGAAAGAAAGATCA...

output:

11
9
11
12
11
7
11
9
10
8

result:

ok 10 tokens

Test #9:

score: 4
Accepted
time: 0ms
memory: 2360kb

input:

10
GAACAAACCATTGAGTTCATTGCACATCCGATACCTAAAAAACACTACAT
ACCCAGATCTACTCTCTTCTAACACTGATTGACAATTTGCTGAACC...

output:

9
10
9
9
5
11
11
11
7
13

result:

ok 10 tokens

Test #10:

score: 4
Accepted
time: 0ms
memory: 2264kb

input:

19
GACTTACGCCCAAAAATCCCCGAGACGTCACTAAATCTCAAAAATTATTC
CTTCTAAATCTAATCCTATGTCGCCCTCCGCTCTGGGACTATTCTC...

output:

9
9
7
10
4
2
4
4
3
5
4
3
4
4
4
4
2
3
6

result:

ok 19 tokens

Test #11:

score: 4
Accepted
time: 0ms
memory: 2356kb

input:

19
TGCTTCCTGCATCGAAATGT
CACAAGTGAAATTGTTTACT
TGTTCAAACCAACCCTCTTC
ACTCTACCTGTCGCCAAATA
TGACACCTCATCG...

output:

3
4
3
2
3
4
4
4
2
1
4
2
3
3
3
8
11
13
10

result:

ok 19 tokens

Test #12:

score: 4
Accepted
time: 1ms
memory: 1268kb

input:

50
AAACAAATCT
TCCCAACAAC
TCTCAATTCC
CTCCATCTAA
GATAAACTCA
ACTTACGTTA
CTAATTCCCA
CTCTCACTCA
AATAATGCA...

output:

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

result:

ok 50 tokens

Test #13:

score: 4
Accepted
time: 0ms
memory: 1268kb

input:

10
DOEHWYGHXGOJAQHEFUFFVAKMLNHMOXSUZWMNATIULQZQMCWZJA
NXJHYTEVCSYBGVASDYEQFCAYDXPYNDJQQJWLNJOWNOIWRX...

output:

0
0
0
1
0
0
1
0
0
1

result:

ok 10 tokens

Test #14:

score: 0
Wrong Answer
time: 12ms
memory: 2424kb

input:

62
AAATTTTTTTTATTTATTATTTTTTTTAATAAATTATATAATATTTTTAATTATTTTTTATTAATTTTAATTATTAATTATATTAAATTTTATTTAT...

output:

323
318
15
13
15
9
12
14
14
12
16
14
15
14
15
16
12
14
15
10
12
15
12
12
13
12
11
15
15
14
15
7
15
1...

result:

wrong answer 1st words differ - expected: '329', found: '323'

Test #15:

score: 0
Wrong Answer
time: 0ms
memory: 1196kb

input:

5
TTATAATTTTTTTATTTTTTATTTATTTATTTAATATTTTTTATTTATTAAATATAATTTTTTATTTTTTTATTATTTAAATTTTTTATATAAAATAA...

output:

309
323
328
311
316

result:

wrong answer 1st words differ - expected: '313', found: '309'

Test #16:

score: 0
Wrong Answer
time: 0ms
memory: 1192kb

input:

5
TTATTATATTATTTTTTTATTAAATTATTTATATAAATAAATTATTTTTATTTTATTTTATTATTTTTATTTATTATTTTTTTATTTAAAAATTTTAT...

output:

311
307
311
309
330

result:

wrong answer 1st words differ - expected: '333', found: '311'

Test #17:

score: 0
Wrong Answer
time: 1ms
memory: 1196kb

input:

5
TAATTTATTTTATTTATTAAATTTTTATTTTAATAATATTTTAATTATTTATATTTTATTAATAATAATTTTTTTATTTAAATTTAATTATTTTTTTA...

output:

316
319
324
320
300

result:

wrong answer 1st words differ - expected: '323', found: '316'

Test #18:

score: 0
Wrong Answer
time: 0ms
memory: 1192kb

input:

5
TTTATTTTTTTTTATTTTTATTTATTTAATTTATAATATTATTTTTTTTATAATTTTTTTTTTTTTATAAAATATTTTTATTTTTTTAATATATTTTT...

output:

310
326
312
314
327

result:

wrong answer 1st words differ - expected: '324', found: '310'

Test #19:

score: 0
Wrong Answer
time: 13ms
memory: 2420kb

input:

62
ATTTTTTTATATTTTTTTTTTTTTATTTTTATTATTATTATTTTTATTTA
ATTATATTTTATTAATTTTTAATTTTTTATTTTAATTTTAATTAAT...

output:

8
15
15
11
14
9
15
11
16
14
11
13
16
13
15
12
15
15
13
14
14
14
13
14
15
10
14
15
15
14
13
15
13
14
...

result:

wrong answer 61st words differ - expected: '331', found: '322'

Test #20:

score: 0
Wrong Answer
time: 2ms
memory: 1484kb

input:

110
TATTAAATATATTAAATTTTTTTTATTAATTTATTATTTATTATTATATTATATTTTTTATATTTTTATAAAAATTTATTTTATTTATAATTAATA...

output:

97
91
93
84
93
89
91
94
85
86
3
4
6
6
6
6
6
4
3
4
3
5
5
6
5
4
6
6
4
6
5
4
4
2
3
4
3
4
5
4
5
6
5
4
2
...

result:

wrong answer 1st words differ - expected: '98', found: '97'

Test #21:

score: 0
Wrong Answer
time: 3ms
memory: 1488kb

input:

110
ATATATTTTTAATTTTTTAT
TTTTTTTAATTTTTATTATT
TTTATAAATAAAATTTTTTT
AATATTTATAATAATTTTAT
AAATTTATAATA...

output:

5
4
5
5
5
5
6
5
3
6
3
5
4
6
5
6
6
6
4
5
4
6
4
6
4
5
5
3
5
4
6
3
5
5
4
3
2
4
6
4
6
6
5
4
3
3
3
5
2
4
...

result:

wrong answer 102nd words differ - expected: '87', found: '84'

Test #22:

score: 0
Wrong Answer
time: 0ms
memory: 1192kb

input:

5
SXKKWHGPZMREKWJWXIEXUZXLQGVRPQKXQLASTFLUAPAPUSLGRPEINOXUBSXJLAQHQFNXPPBZZAJLXRIQTPNVJPJVAWXWINTTKO...

output:

17
14
17
22
17

result:

wrong answer 1st words differ - expected: '18', found: '17'

Test #23:

score: 0
Wrong Answer
time: 31ms
memory: 2172kb

input:

2
TATATACAACATCTAGATCTCACTTGATTTCACTATTCAATTCCCATGTCCATACAACCGACTCAAATTCTAATTTTAGATTTACTAACCCATTACCG...

output:

203676
203991

result:

wrong answer 1st words differ - expected: '304734', found: '203676'

Test #24:

score: 0
Wrong Answer
time: 31ms
memory: 2168kb

input:

2
CCTGTCTATCAACCTCTAACACATAATCGGACTATGACCACTTGATTTTACCACTACCAGCTCAAATGAACACACTCTCTTTTCTTATTACTATCAAC...

output:

203867
203691

result:

wrong answer 1st words differ - expected: '305146', found: '203867'

Test #25:

score: 0
Wrong Answer
time: 21ms
memory: 2168kb

input:

2
TACCAACCTACTCGAGCTCCCTCTACAATTACGACTTCCTGAACTACCATACCAAACTGCTCTCGAATTGTATCGACATGATTAAGTCCCAATTCGAT...

output:

203413
203672

result:

wrong answer 1st words differ - expected: '304736', found: '203413'

Test #26:

score: 0
Wrong Answer
time: 27ms
memory: 2168kb

input:

2
CACACATTCTCTCTTATTCAGCCTATCCGTGAAAGTTGACATATATCATGTCAAAATGCCATCTTAACTTAATAACGTAAATCTACCGATCCATTTAT...

output:

204021
203797

result:

wrong answer 1st words differ - expected: '304589', found: '204021'

Test #27:

score: 0
Wrong Answer
time: 30ms
memory: 1488kb

input:

84
ATAGACCCCCCAACACCGCTACTAACTTTCCCTGATTATCCCCTGGCATCTCCATTGTTAAAACGCCCCTATTACGTAATTTTTGCGCGATATTTTA...

output:

61273
61220
60965
61112
2035
2036
2008
2048
2025
2015
2044
2023
2029
2035
2059
2062
2020
2023
2026
2...

result:

wrong answer 1st words differ - expected: '91027', found: '61273'

Test #28:

score: 0
Wrong Answer
time: 27ms
memory: 1484kb

input:

84
CTCCTCACCTTTAACGATCATACTCAATAACAGAACACCATTCGACCCCCTTTAACCATATGCCACGCCTGACTATTTCACTTCCTCCCTTGCCGAT...

output:

2023
2010
2035
2017
2023
2044
2004
2049
1989
2040
2074
2114
1995
2099
2071
2092
2027
2044
2086
2080
...

result:

wrong answer 1st words differ - expected: '2938', found: '2023'

Test #29:

score: 0
Wrong Answer
time: 37ms
memory: 2172kb

input:

10001
AAAGACGCTCCAACCAGCTATCTTTCCAAATGTTCCTCTACCCTACCTCAGCTTTCGTCCAATCCCAGAACCCTAGTTAATATAACTCTAAATA...

output:

203850
20
20
22
18
20
15
19
20
20
22
17
20
18
18
17
19
17
16
20
20
20
19
18
17
18
23
16
16
15
15
21
...

result:

wrong answer 1st words differ - expected: '304838', found: '203850'

Test #30:

score: 0
Wrong Answer
time: 32ms
memory: 2172kb

input:

2501
CGTCCACGTTGTCGCCCACTATATAAACTATCTCCCACTATGAAAGGCCCCTTTTAATAACCTCATCTCTTAAAGATAAATCCCTAATTACCCTA...

output:

72
87
82
85
79
80
83
82
86
77
77
78
83
85
74
78
86
76
79
72
78
78
80
81
82
76
73
83
81
86
80
69
77
8...

result:

wrong answer 1st words differ - expected: '111', found: '72'

Test #31:

score: 0
Time Limit Exceeded

input:

100000
TAAATTTACTACTCCTACCA
AACACATAAAACGCTTCTCA
CATATCTAAAAATAAACCTC
CGTCCCAACCTACCTCGCCT
TACGACCCA...

output:

3
3
3
3
1
3
3
4
2
2
4
4
2
3
4
4
4
3
3
2
2
3
1
3
4
2
5
3
4
3
1
3
4
3
5
2
4
5
5
3
3
3
4
3
3
3
2
3
3
0
...

result:


Test #32:

score: 0
Wrong Answer
time: 266ms
memory: 1364kb

input:

250005
TAGCAAATTTTACATAGCAATAATCACATAACTTACCTCATACTATAATAGAATCATTAACACCATGCCATCCCCTCTCATGTATACCTCTTT...

output:

20427
20418
20408
20471
20301
0
1
0
0
1
0
0
1
1
0
1
0
0
0
0
1
1
1
0
0
1
0
1
1
0
1
0
1
0
1
1
0
0
0
0
...

result:

wrong answer 1st words differ - expected: '30478', found: '20427'

Test #33:

score: 0
Wrong Answer
time: 32ms
memory: 2172kb

input:

1001
TAATACCTTCCCCCTTAATGAACCCATAGACCTTTCCCTTTAATAATTCTAATACAACCCTGGCCCCACACACAAATATAAACCAGGGTCAAAAA...

output:

190
201
203
218
197
194
200
192
201
211
201
191
200
199
192
200
204
205
198
208
199
205
211
197
196
...

result:

wrong answer 1st words differ - expected: '284', found: '190'

Test #34:

score: 0
Wrong Answer
time: 9ms
memory: 2172kb

input:

2
NPPZPXGAOITHNUMEIZSXQMQAZPYNBVBKYSJGJDMGEYQRYSPFBKJOJYIFRAJWFCQYOATYKHTBWXAKPVKFAXJBDBWIXDUBGRMGVG...

output:

25787
25776

result:

wrong answer 1st words differ - expected: '37993', found: '25787'