QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#220705 | #5474. Incredibly Cute Penguin Chicks | acagubica | WA | 1152ms | 205768kb | C++14 | 2.2kb | 2023-10-20 18:17:19 | 2023-10-20 18:17:20 |
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;
if(fM[X][m][mid]>=MOD)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];
if(ukupno>=MOD)ukupno-=MOD;
mid-=mid&(-mid);
}
dp[ID]+=ukupno;
}
}
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5704kb
input:
ICPC
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 5692kb
input:
CCCIIIPPP
output:
69
result:
ok single line: '69'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5596kb
input:
PICCICCIPPI
output:
24
result:
ok single line: '24'
Test #4:
score: -100
Wrong Answer
time: 1152ms
memory: 205768kb
input:
PCPPCCICPICPCPCPCCPPIPPPIICCCICPICCPPPIPCCCCICCIICPCCICCCPCICIPPIPIPIPPCCPCIPPCCPPCCIPPPIPPCIICIIIPPCIPPICPPICCPIICCCCCCCICPCCPPIPIPICPCIICPCCIPICCCPPCPIIICPCPPPIIIIICCCPCICCPPCPPCICIIIPIPICPCPPPPICPCPIPIIICCICPCIPPICCICPIIPPCCCIICPCPCCICCPICPPPPPPICCCIPCCICICIPICIIICCICPCIPIICPIPIIICCPCCIIPCCCCPIPI...
output:
-1263180722
result:
wrong answer 1st lines differ - expected: '216523282', found: '-1263180722'