結果
| 問題 |
No.996 Phnom Penh
|
| ユーザー |
|
| 提出日時 | 2020-02-24 15:20:38 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 18 ms / 2,000 ms |
| コード長 | 1,820 bytes |
| コンパイル時間 | 1,147 ms |
| コンパイル使用メモリ | 118,404 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-12 05:17:19 |
| 合計ジャッジ時間 | 2,901 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;
int solve1(string& s)
{
int n = s.size();
int i = 0;
int ans = 0;
string t;
while(i < n){
if(s.substr(i, 5) == "phnom"){
t += "penh";
i += 5;
++ ans;
}
else{
t += s[i];
++ i;
}
}
s = move(t);
return ans;
}
int solve2(string& s)
{
if(s.find('h') == string::npos && s.find('e') == string::npos)
return 0;
int n = s.size();
string t;
for(int i=0; i<n; ++i){
if(s[i] != 'h'){
if(s[i] == 'e')
t += 'h';
else
t += s[i];
}
}
s = move(t);
return 1;
}
int main()
{
string s;
cin >> s;
int ans = 0;
for(int i=0; i<2; ++i){
ans += solve1(s);
ans += solve2(s);
}
int n = s.size();
int maxLen = (s.find('h') == string::npos)? 0 : 1;
int i = 0;
while(i < n){
if(s.substr(i, 5) == "phnom"){
i += 5;
int len = 1;
while(i < n && s.substr(i, 2) == "om"){
i += 2;
++ len;
}
ans += len;
maxLen = max(maxLen, len + 1);
}
else{
++ i;
}
}
ans += maxLen;
cout << ans << endl;
return 0;
}