結果
問題 | No.996 Phnom Penh |
ユーザー |
![]() |
提出日時 | 2020-02-21 21:58:09 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,325 bytes |
コンパイル時間 | 2,391 ms |
コンパイル使用メモリ | 213,196 KB |
最終ジャッジ日時 | 2025-01-09 01:32:14 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 WA * 3 |
ソースコード
#pragma GCC optimize ("Ofast")#include<bits/stdc++.h>using namespace std;inline void rd(char &c){int i;for(;;){i = getchar_unlocked();if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){break;}}c = i;}inline int rd(char c[]){int i;int sz = 0;for(;;){i = getchar_unlocked();if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){break;}}c[sz++] = i;for(;;){i = getchar_unlocked();if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){break;}c[sz++] = i;}c[sz]='\0';return sz;}inline void wt_L(char a){putchar_unlocked(a);}inline void wt_L(long long x){int s=0;int m=0;char f[20];if(x<0){m=1;x=-x;}while(x){f[s++]=x%10;x/=10;}if(!s){f[s++]=0;}if(m){putchar_unlocked('-');}while(s--){putchar_unlocked(f[s]+'0');}}template<class S, class T> inline S chmax(S &a, T b){if(a<b){a=b;}return a;}int N;char S[200000+2];int main(){int Lj4PdHRW, i;int k;int ok;long long res = 0;N = rd(S);for(Lj4PdHRW=(0);Lj4PdHRW<(1);Lj4PdHRW++){int i;k = ok = 0;for(i=(0);i<(N);i++){if(i+4 < N && S[i]=='p' && S[i+1]=='h' && S[i+2]=='n' && S[i+3]=='o' && S[i+4]=='m'){res++;S[k++] = 'p';S[k++] = 'e';S[k++] = 'n';S[k++] = 'h';ok++;i += 4;continue;}S[k++] = S[i];}N = k;k = 0;for(i=(0);i<(N);i++){if(S[i]=='e' || S[i]=='h'){k++;}}if(k){k = 0;for(i=(0);i<(N);i++){if(S[i]=='h'){continue;}if(S[i]=='e'){S[k++] = 'h';continue;}S[k++] = S[i];}res++;ok++;}N = k;if(!ok){break;}}int mx = -1;int tmp;for(i=(0);i<(N);i++){if(i+2 < N && S[i]=='p' && S[i+1]=='h' && S[i+2]=='n'){tmp = 0;while(i+4+2*tmp < N && S[i+3+2*tmp]=='o' && S[i+4+2*tmp]=='m'){tmp++;}chmax(mx, tmp);res += tmp;}}res += mx + 1;wt_L(res);wt_L('\n');return 0;}// cLay varsion 20200217-1// --- original code ---// int N;// char S[2d5+2];// {// int k, ok;// ll res = 0;// rd(S@N);//// rep(1){// k = ok = 0;// rep(i,N){// if(i+4 < N && S[i]=='p' && S[i+1]=='h' && S[i+2]=='n' && S[i+3]=='o' && S[i+4]=='m'){// res++;// S[k++] = 'p';// S[k++] = 'e';// S[k++] = 'n';// S[k++] = 'h';// ok++;// i += 4;// continue;// }// S[k++] = S[i];// }// N = k;//// k = 0;// rep(i,N) if(S[i]=='e' || S[i]=='h') k++;// if(k){// k = 0;// rep(i,N){// if(S[i]=='h') continue;// if(S[i]=='e') S[k++] = 'h', continue;// S[k++] = S[i];// }// res++;// ok++;// }// N = k;//// if(!ok) break;// }//// int mx = -1, tmp;// rep(i,N){// if(i+2 < N && S[i]=='p' && S[i+1]=='h' && S[i+2]=='n'){// tmp = 0;// while(i+4+2tmp < N && S[i+3+2tmp]=='o' && S[i+4+2tmp]=='m') tmp++;// mx >?= tmp;// res += tmp;// }// }// res += mx + 1;//// wt(res);// }