結果

問題 No.996 Phnom Penh
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2020-02-22 15:25:50
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 2,647 bytes
コンパイル時間 2,382 ms
コンパイル使用メモリ 201,108 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 23:12:57
合計ジャッジ時間 3,865 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_06 AC 1 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 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 31 ms
5,376 KB
testcase_14 AC 31 ms
5,376 KB
testcase_15 AC 32 ms
5,376 KB
testcase_16 AC 32 ms
5,376 KB
testcase_17 AC 33 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 24 ms
5,376 KB
testcase_25 AC 19 ms
5,376 KB
testcase_26 AC 24 ms
5,376 KB
testcase_27 AC 18 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














string S;
//---------------------------------------------------------------------------------------------------
pair<string, int> ope1(string s) {
	int cnt = 0;
	string res = "";
	int n = s.length();
	rep(i, 0, n) {
		if (i + 5 <= n && s.substr(i, 5) == "phnom") {
			cnt++;
			res += "penh";
			i += 4;
		}
		else res += s[i];
	}
	return { res, cnt };
}
pair<string,int> ope2(string s) {
	int cnt = 0;
	string res = "";
	fore(c, s) {
		if (c == 'h') cnt = 1;
		else res += c;
	}
	fore(c, res) if (c == 'e') {
		c = 'h';
		cnt = 1;
	}
	return { res, cnt };
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> S;

	int ans = 0;
	rep(i, 0, 2) {
		int tot = 0, res;
		string s = S;
		if (i == 0) tie(s, tot) = ope2(s);

		rep(_, 0, 5) {
			int res;
			tie(s, res) = ope1(s);
			tot += res;
			tie(s, res) = ope2(s);
			tot += res;
		}

		int n = s.length();
		int ma = 0;
		rep(i, 0, n - 4) if (s.substr(i, 5) == "phnom") {
			int cnt = 0;
			int j = i + 3;
			while (j < n - 1) {
				if (s.substr(j, 2) != "om") break;
				cnt++;
				j += 2;
			}
			chmax(ma, cnt);
			tot += cnt;
		}

		if (ma == 0) {
			tie(s, res) = ope2(s);
			tot += res;
		} else tot += ma + 1;
		
		chmax(ans, tot);
	}
	cout << ans << endl;
}





0