結果

問題 No.996 Phnom Penh
ユーザー finefine
提出日時 2020-02-22 00:15:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,937 bytes
コンパイル時間 1,552 ms
コンパイル使用メモリ 165,224 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 10:44:24
合計ジャッジ時間 2,534 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 2 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 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 8 ms
5,376 KB
testcase_14 AC 7 ms
5,376 KB
testcase_15 AC 7 ms
5,376 KB
testcase_16 AC 8 ms
5,376 KB
testcase_17 AC 8 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 5 ms
5,376 KB
testcase_25 AC 5 ms
5,376 KB
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 4 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    bool f2 = false;
    for (char c : s) {
        if (c == "phnom"[state]) {
            state++;
            if (state == 5) {
                state = 3;
                cnt += 2;
                f = true;
            }
        } else {
            if ((state > 1 && !f) || c == 'e') f2 = true; 
            state = (c == 'p');
            cnt += f;
            f = false;
        }
    }
    if (state > 1 && !f) f2 = true;
    cnt += f + f2;
    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;
}
0