結果

問題 No.996 Phnom Penh
ユーザー leaf_1415leaf_1415
提出日時 2020-02-21 23:34:55
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,430 bytes
コンパイル時間 927 ms
コンパイル使用メモリ 60,796 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-17 09:31:14
合計ジャッジ時間 1,939 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 WA -
testcase_14 AC 23 ms
6,944 KB
testcase_15 AC 23 ms
6,944 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 WA -
testcase_25 AC 22 ms
6,940 KB
testcase_26 AC 21 ms
6,940 KB
testcase_27 AC 15 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#define llint long long
#define mod 1000000007

using namespace std;

string s;

llint calc(string &s)
{
	llint ret = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'e') ret = 2;
		if(s[i] == 'h') ret = 1;
	}

	llint mx = 0, sum = 0, phn = 0, penh = 0;
	for(int i = 0; i < s.size(); i++){
		if(i+2 < s.size() && s.substr(i, 3) == "phn"){
			i += 3;
			llint cnt = 0;
			for(; i < s.size();){
				if(i+1 < s.size() && s.substr(i, 2) == "om"){
					cnt++;
					i+=2;
				}
				else break;
			}
			if(cnt >= 1){
				mx = max(mx, cnt);
				sum += cnt;
			}
			i--;
		}
		if(i+3 < s.size() && s.substr(i, 4) == "penh"){
			i += 4;
			llint cnt = 1;
			for(; i < s.size();){
				if(i+1 < s.size() && s.substr(i, 2) == "om"){
					cnt++;
					i+=2;
				}
				else break;
			}
			mx = max(mx, cnt);
			sum += cnt;
			penh++;
			i--;
		}
	}
	if(mx >= 1){
		llint tmp = sum + mx + 1 - penh;
		ret = max(ret, tmp);
	}

	return ret;
}

bool ope(string &s)
{
	string t = s;
	s = "";

	bool flag = false;
	for(int i = 0; i < t.size(); i++){
		if(t[i] == 'h'){
			flag = true;
		}
		else if(t[i] == 'e'){
			s += 'h';
			flag = true;
		}
		else s += t[i];
	}
	return flag;
}

int main(void)
{
  ios::sync_with_stdio(0);
  cin.tie(0);

  cin >> s;
	llint ans = calc(s);
	if(ope(s)) ans = max(ans, calc(s)+1);
	if(ope(s)) ans = max(ans, calc(s)+2);
	cout << ans << endl;

  return 0;
}
0