結果

問題 No.996 Phnom Penh
ユーザー QCFiumQCFium
提出日時 2020-02-21 22:51:14
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,362 bytes
コンパイル時間 1,723 ms
コンパイル使用メモリ 171,964 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-08 22:30:57
合計ジャッジ時間 2,914 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 20 WA * 5
権限があれば一括ダウンロードができます

ソースコード

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;
		while (index + 1 < (int) s.size() && s[index] == 'o' && s[index + 1] == 'm') index += 2, r0++;
		s[0] = 'p';
		s[1] = 'e';
		s[2] = 'n';
		s[3] = 'h';
		s.erase(s.begin() + 4, s.begin() + index);
	}
	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