-
Notifications
You must be signed in to change notification settings - Fork 0
/
countPATS.cpp
45 lines (40 loc) · 876 Bytes
/
countPATS.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<iostream>
#include<string.h>
char dataa[100005];
int tcnt[100005];
long long atcnt[100005];
using namespace std;
int main(){
memset(dataa, 0, sizeof(dataa));
memset(tcnt, 0, sizeof(tcnt));
memset(atcnt, 0, sizeof(atcnt));
scanf("%s", dataa);
int len=0;
for(int i=0;i<100005&&dataa[i]!=0;i++){
len++;
}
int tcount=0;
for(int i=len-1;i>=0;i--){
if(dataa[i]=='T'){
tcount++;
}
tcnt[i]=tcount;
}
long long atcount=0;
for(int i=len-1;i>=0;i--){
if(dataa[i]=='A'){
atcount+=tcnt[i+1];
}
atcnt[i]=atcount;
}
long long pats=0;
for(int i=0;i<100005&&dataa[i]!=0;i++){
if(dataa[i]=='P'){
pats+=atcnt[i+1];
}
if(pats>1000000007){
pats=pats%1000000007;
}
}
cout<<pats;
}