結果

問題 No.996 Phnom Penh
ユーザー QCFiumQCFium
提出日時 2020-02-21 22:21:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 944 bytes
コンパイル時間 2,619 ms
コンパイル使用メモリ 167,300 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 07:42:00
合計ジャッジ時間 2,656 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
5,376 KB
testcase_20 WA -
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 WA -
testcase_25 AC 9 ms
5,376 KB
testcase_26 AC 9 ms
5,376 KB
testcase_27 AC 8 ms
5,376 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;
}



int solve(const std::string &s) {
	int n = s.size();
	std::vector<int> all;
	for (int i = 0; i + 4 < n; i++) {
		if (s.substr(i, 5) == "phnom") {
			all.push_back(0);
			i += 5;
			while (i + 1 < n && s[i] == 'o' && s[i + 1] == 'm') i += 2, all.back()++;
			i--;
		}
	}
	if (all.size()) return std::accumulate(all.begin(), all.end(), 0) + *std::max_element(all.begin(), all.end()) + all.size() + 2;
	else if (std::count(s.begin(), s.end(), 'e')) return 2;
	else if (std::count(s.begin(), s.end(), 'h')) return 1;
	else return 0;
}

int main() {
	std::string s;
	std::cin >> s;
	int n = s.size();
	
	int res = solve(s);
	std::string t;
	for (auto c : s) if (c != 'h') t.push_back(c);
	std::replace(t.begin(), t.end(), 'e', 'h');
	res = std::max(res, solve(t) + 1);
	printf("%d\n", res);
	return 0;
}
0