QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#220706 | #5474. Incredibly Cute Penguin Chicks | acagubica | TL | 5875ms | 744956kb | C++14 | 2.2kb | 2023-10-20 18:18:27 | 2023-10-20 18:18:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
string S;
int sol,A[1000005],B[1000005],C[1000005];
long long dp[1000009];
long long MOD=998244353;
struct slog{
int ID;
int m[3],v[3],mid[3];
}SVE[1000009];
int GLOBcmp=0;
bool cmp(slog x, slog y){
return x.v[GLOBcmp]<y.v[GLOBcmp];
}map<int,vector<slog>>M[3];
map<int,vector<int>>fM[3];
map<int,bool>imamM[3];
vector<int>ALLm[3];
void update_fenvicks(int ID){
long long dodaj=dp[ID];
slog sl=SVE[ID];
for(int X=0; X<=2; X++){
int m=sl.m[X];
int mid=sl.mid[X];
while(mid<fM[X][m].size()-2){
fM[X][m][mid]+=dodaj;
fM[X][m][mid]%=MOD;
mid+=mid&(-mid);
}
}
}
void add_fenvicks_to_dp(int ID){
slog sl=SVE[ID];
for(int X=0; X<=2; X++){
int m=sl.m[X];
int mid=sl.mid[X]-1;
long long ukupno=0;
while(mid>0){
ukupno+=fM[X][m][mid];
ukupno%=MOD;
mid-=mid&(-mid);
}
dp[ID]+=ukupno;
dp[ID]%=MOD;
}
}
int main(){
cin>>S;
S=' '+S+' ';
for(int i=1; i<S.size()-1; i++){
A[i]=A[i-1]+(S[i]=='I');
B[i]=B[i-1]+(S[i]=='P');
C[i]=C[i-1]+(S[i]=='C');
}
for(int i=0; i<S.size()-1; i++){
SVE[i].ID=i;
SVE[i].m[0]=A[i]-B[i];
SVE[i].m[1]=A[i]-C[i];
SVE[i].m[2]=B[i]-C[i];
SVE[i].v[0]=3*C[i]-i;
SVE[i].v[1]=3*B[i]-i;
SVE[i].v[2]=3*A[i]-i;
}
for(int i=0; i<S.size()-1; i++){
slog sl=SVE[i];
for(int X=0; X<=2; X++){
M[X][sl.m[X]].push_back(sl);
if(!imamM[X][sl.m[X]])ALLm[X].push_back(sl.m[X]);
imamM[X][sl.m[X]]=true;
}
}
for(int X=0; X<=2; X++){
for(int i=0; i<ALLm[X].size(); i++){
int m=ALLm[X][i];
GLOBcmp=X;
sort(M[X][m].begin(),M[X][m].end(),cmp);
vector<slog>v=M[X][m];
int mid=1;
for(int j=0; j<v.size()-1; j++){
SVE[v[j].ID].mid[X]=mid;
if(v[j].v[X]<v[j+1].v[X])mid++;
}
SVE[v[v.size()-1].ID].mid[X]=mid;
for(int i=0; i<=mid+3; i++)fM[X][m].push_back(0);
}
}
dp[0]=1;
update_fenvicks(0);
for(int i=1; i<S.size()-1; i++){
add_fenvicks_to_dp(i);
update_fenvicks(i);
}
cout<<dp[S.size()-2]<<"\n";
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5660kb
input:
ICPC
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5656kb
input:
CCCIIIPPP
output:
69
result:
ok single line: '69'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5848kb
input:
PICCICCIPPI
output:
24
result:
ok single line: '24'
Test #4:
score: 0
Accepted
time: 1025ms
memory: 205852kb
input:
PCPPCCICPICPCPCPCCPPIPPPIICCCICPICCPPPIPCCCCICCIICPCCICCCPCICIPPIPIPIPPCCPCIPPCCPPCCIPPPIPPCIICIIIPPCIPPICPPICCPIICCCCCCCICPCCPPIPIPICPCIICPCCIPICCCPPCPIIICPCPPPIIIIICCCPCICCPPCPPCICIIIPIPICPCPPPPICPCPIPIIICCICPCIPPICCICPIIPPCCCIICPCPCCICCPICPPPPPPICCCIPCCICICIPICIIICCICPCIPIICPIPIIICCPCCIIPCCCCPIPI...
output:
216523282
result:
ok single line: '216523282'
Test #5:
score: 0
Accepted
time: 1050ms
memory: 212532kb
input:
ICIPCICCIPIPIIPPCPCICICPCPCPIIICICPPICCICPIPCPCIIPPIPCCIPIPIPIICCICICCCIPPIIPCPPCIIICCICCCCCCPIPICCIPIICIICPIPCCICPPCCIPIPIICCCPCCIPCPPCCIIIIIPCIPIIPICIIIPIICCCIPPPIPICIIIICIIIPICIICPIPCCICIPCCIPICCCPPIPIIPICPPCPICIPIPPPPPCIPCCIPPICIPCICPCCCCPPIIIPCPICCICIPIIPICPIIIIPPPCPIIIPCCPPIIPPICPIIICCCPICPPIC...
output:
977504498
result:
ok single line: '977504498'
Test #6:
score: 0
Accepted
time: 1094ms
memory: 211264kb
input:
PPCCCICCIPPICCPCCCCIPPPIICPIPIPPPPIPPPPPPCPIPICCPCCPICPIPPPIIPIPIIPPCCPIICPPIIIPPCCCIIPCCIPCCCCCCIIIPIPCICCIICIIICCCCPCCICPPCCPCCIPICCPPIIPIIPIPCIIPIIPPPCCIPCPCCICCIPICPPPCIPPIPCCPCPCCIPIICCIPCCIPPCPCIPICIICPPICIIICIPIIIIIPCCCPPIPPPCIICIIIPPCIPCIPCIICCCCPIPCPICICPIPCPPIPIPICCPCCCCPCIPCPPCCIPCCCCCPII...
output:
785880133
result:
ok single line: '785880133'
Test #7:
score: 0
Accepted
time: 1047ms
memory: 207496kb
input:
ICIPCPIPCCCCCCCPCCPCCIPCPCPIPPCPIPCICPPIPPPPICPIIPPIICPICPICPPICICICCCIIPCPPCCICCCCPIICPPPIPIPCICPIPPPPCCPICPCPICICPPIIIICIICPPIPIIICCCCPIPIIPICCCIPCCPPCPPPPIIIIICIPCPCCPIIICICIPPCCPIPPCIIPCCCIIICPCIPCIIIIPCIIPCIICCCIPPIPPCIIPCICIPIIPICCICCPCPIICCCIPIICCCPIPPCCIIIICPPIICPCPCIPPPCPCICPPIPIPCCPIPPPIPI...
output:
687587235
result:
ok single line: '687587235'
Test #8:
score: 0
Accepted
time: 1079ms
memory: 210188kb
input:
IICCCIPIIIIIPICIICPCPCIICCIIICCCIIPICICCCPCPCPPPIIPIPPICIICICIPIICCICCIIIPCIICCPPIPICIPPCPCPCPIICCIIICIPPICCICPPIPPPPICPCPIPCCCPCPCPPPPIICPCIIIIIIIPIPIICICCPPIIPPCICPCPCIPCPICPPPICCICIICPPIPPPIPIPIPPCIPPCIPPCPPPIICICCCPICIPPIPCCPIIPPCIPPICCIIIPPPPPIIPPICPCPCIPPCCPCIIIPPICCCIIIIICIPPIIICPCIIICPPCPCPP...
output:
698376687
result:
ok single line: '698376687'
Test #9:
score: 0
Accepted
time: 1064ms
memory: 208412kb
input:
IIPICCCCIPPCCPICCIIPPPCIPCCPPIPIICICPCCIIPPCCCICICPPICCICPPIICIIPICPICIPPPPCPCCPIICCPPIPPCIIIIPICICICCIIPPCICCCCCPICPIPCPPCCPPICPICCCICCIPICCICPIICCPIPIPICCPPCCPCPCCPICCPICCCCCCIPIICPIPICICCPIIPIPICIICIPPPIPCICIPIPPICPICICPPICICCIPCIPPPCIPIIPPPIICICPPPIICCCPIIICIPIPPICICIPPPCCPCCIIPCCCPPPCPICPICPPCP...
output:
850857669
result:
ok single line: '850857669'
Test #10:
score: 0
Accepted
time: 5875ms
memory: 744956kb
input:
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII...
output:
709758735
result:
ok single line: '709758735'
Test #11:
score: -100
Time Limit Exceeded
input:
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...