結果
| 問題 |
No.996 Phnom Penh
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2020-02-21 22:10:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 53 ms / 2,000 ms |
| コード長 | 2,014 bytes |
| コンパイル時間 | 2,801 ms |
| コンパイル使用メモリ | 208,280 KB |
| 最終ジャッジ日時 | 2025-01-09 01:35:42 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//INSERT ABOVE HERE
deque<char> op(deque<char> dd){
deque<char> rs;
for(char &c:dd){
if(c=='h') continue;
rs.emplace_back(c);
}
for(char &c:rs){
if(c=='e') c='h';
}
return rs;
}
signed main(){
string s;
cin>>s;
vector<deque<char>> vs;
for(char c:s){
if(vs.empty()||c=='p') vs.emplace_back();
vs.back().emplace_back(c);
}
Int ans=0;
deque<char> dc;
for(char c:"phnom"s) dc.emplace_back(c);
Int max_num=0;
for(auto dd:vs){
// cout<<string(dd.begin(),dd.end())<<endl;
Int ex_e=1;
Int ex_h=1;
Int num=0;
while(1){
Int flg=0;
if(dd.size()>=5){
flg=1;
for(Int i=0;i<5;i++)
flg&=dd[i]==dc[i];
}
if(!flg){
if(count(dd.begin(),dd.end(),'h')||count(dd.begin(),dd.end(),'e')){
dd=op(dd);
num++;
}else{
break;
}
}else{
break;
}
}
while(1){
Int change=0;
Int flg=0;
if(dd.size()>=5){
flg=1;
for(Int i=0;i<5;i++)
flg&=dd[i]==dc[i];
}
if(flg){
dd.pop_front();
dd.pop_front();
dd.pop_front();
dd.pop_front();
dd.pop_front();
change++;
}else{
while(count(dd.begin(),dd.end(),'h')||count(dd.begin(),dd.end(),'e')){
dd=op(dd);
num++;
}
break;
}
if(ex_h||ex_e){
dd=op(dd);
ex_h=count(dd.begin(),dd.end(),'h');
ex_e=count(dd.begin(),dd.end(),'e');
}
dd.emplace_front('n');
dd.emplace_front('h');
dd.emplace_front('p');
num++;
if(!change) break;
ans+=change;
}
chmax(max_num,num);
}
// cout<<max_num<<endl;
cout<<ans+max_num<<endl;
return 0;
}
beet