結果
問題 | No.996 Phnom Penh |
ユーザー |
![]() |
提出日時 | 2020-02-21 23:10:11 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,600 bytes |
コンパイル時間 | 1,800 ms |
コンパイル使用メモリ | 169,204 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-09 02:10:17 |
合計ジャッジ時間 | 2,833 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 2 WA * 23 |
ソースコード
#include<bits/stdc++.h> #define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i) #define rep(i,a,b) for(int i=int(a);i<int(b);++i) #define All(x) (x).begin(),(x).end() #define rAll(x) (x).rbegin(),(x).rend() using namespace std; using ll = long long; int main(){ string s;cin>>s; int ans=0; while(1){ string t; int tmp=ans; bool flag1=false,flag2=false; REP(i,s.size()){ if(i+3<s.size()&&s.substr(i,4)=="penh"){ t.push_back('B'); flag1=true; i+=3; } if(i+2<s.size()&&s.substr(i,3)=="phn"){ t.push_back('B'); flag2=true; i+=2; } else if(i+1<s.size()&&s.substr(i,2)=="om"){ t.push_back('A'); i++; } else if(s[i]=='h'){ flag1=true; } else{ t.push_back(s[i]); } } if(flag1&&!flag2) tmp++; int cnt=0; bool B=false; s.clear(); for(int i=(int)t.size()-1;i>=0;--i){ if(t[i]=='A'){ cnt++; } else if(t[i]=='B'){ tmp+=2*cnt; cnt=0; B=true; } else if(t[i]=='h') B=true; else{ cnt=0; s.push_back(t[i]); } } reverse(All(s)); if(B) tmp++; if(tmp==ans){ break; } ans=tmp; } cout<<ans<<endl; }