結果
| 問題 | 
                            No.996 Phnom Penh
                             | 
                    
| コンテスト | |
| ユーザー | 
                             QCFium
                         | 
                    
| 提出日時 | 2020-02-21 22:53:10 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,459 bytes | 
| コンパイル時間 | 1,788 ms | 
| コンパイル使用メモリ | 173,424 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-10-08 22:32:35 | 
| 合計ジャッジ時間 | 2,960 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 WA * 2 | 
| other | AC * 20 WA * 5 | 
ソースコード
#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);
	}
	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;
}
            
            
            
        
            
QCFium