結果
| 問題 |
No.996 Phnom Penh
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-22 00:08:05 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,816 bytes |
| コンパイル時間 | 1,387 ms |
| コンパイル使用メモリ | 167,632 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-09 03:28:40 |
| 合計ジャッジ時間 | 2,224 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 15 WA * 10 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int op1(string& s) {
int cnt = 0;
int state = 0;
string res = "";
for (char c : s) {
if (c == "phnom"[state]) {
state++;
if (state == 5) {
res += "penh";
state = 0;
cnt++;
}
} else {
for (int i = 0; i < state; ++i) {
res += "phnom"[i];
}
state = (c == 'p');
res += c;
}
}
for (int i = 0; i < state; ++i) {
res += "phnom"[i];
}
s = res;
return cnt;
}
int op2(string& s) {
int cnt = 0;
string res = "";
for (char c : s) {
if (c == 'h') {
cnt = 1;
continue;
} else if (c == 'e') {
cnt = 1;
res += 'h';
} else {
res += c;
}
}
s = res;
return cnt;
}
int calc(string& s) {
int cnt = 0;
int state = 0;
bool f = false;
for (char c : s) {
if (c == "phnom"[state]) {
state++;
if (state == 5) {
state = 3;
cnt += 2;
f = true;
}
} else {
state = (c == 'p');
cnt += f;
f = false;
}
}
cnt += f;
return cnt;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
string s;
cin >> s;
int ans = 0;
for (int i = 0; i < 2; ++i) {
int cnt1 = op1(s);
ans += cnt1;
//cerr << s << endl;
int cnt2 = op2(s);
ans += cnt2;
//cerr << s << endl;
if (cnt1 == 0 && cnt2 == 0) break;
}
//cerr << s << ans << endl;
ans += calc(s);
cout << ans << "\n";
return 0;
}