結果

問題 No.996 Phnom Penh
ユーザー QCFiumQCFium
提出日時 2020-02-21 22:55:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,487 bytes
コンパイル時間 1,950 ms
コンパイル使用メモリ 169,560 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-30 06:19:46
合計ジャッジ時間 3,040 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rs64() {
	int64_t n;
	scanf("%" SCNd64, &n);
	return n;
}

bool type2(std::string &s) {
	int n = s.size();
	std::string t;
	for (auto c : s) if (c != 'h') t.push_back(c);
	std::replace(t.begin(), t.end(), 'e', 'h');
	bool res = t != s;
	s = t;
	return res;
}

// 1, 2
std::pair<int, int> solve(std::string s) {
	int r0 = 0, r1 = 0;
	while (1) {
		while (s.substr(0, 5) != "phnom") {
			if (!type2(s)) break;
			r1++;
		}
		if (s.substr(0, 5) != "phnom") break;
		r0++;
		int index = 5;
		int cnt = 0;
		while (index + 1 < (int) s.size() && s[index] == 'o' && s[index + 1] == 'm') index += 2, cnt++;
		r0 += cnt;
		r1 += cnt;
		s[0] = 'p';
		s[1] = 'E';
		s[2] = 'n';
		s[3] = 'H';
		s.erase(s.begin() + 4, s.begin() + index);
		for (int i = 0; i < std::min(2, cnt); i++) type2(s);
		s[1] = 'e';
		s[3] = 'h';
	}
	return {r0, r1};
}

int main() {
	std::string s;
	std::cin >> s;
	int n = s.size();
	std::vector<std::pair<int, int> > all;
	int first = n;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'p') {
			first = std::min(first, i);
			int j = i + 1;
			for (; j < n && s[j] != 'p'; j++);
			all.push_back(solve(s.substr(i, j - i)));
		}
	}
	if (first) {
		int cnt = 0;
		std::string tmp = s.substr(0, first);
		while (type2(tmp)) cnt++;
		all.push_back({0, cnt});
	}
	int res = 0, max = 0;
	for (auto &i : all) res += i.first, max = std::max(max, i.second);
	printf("%d\n", res + max);
	return 0;
}
0