結果

問題 No.291 黒い文字列
ユーザー PachicobuePachicobue
提出日時 2017-08-09 16:39:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,877 bytes
コンパイル時間 1,422 ms
コンパイル使用メモリ 166,396 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 08:33:59
合計ジャッジ時間 2,496 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 WA -
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 WA -
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1 ms
6,940 KB
testcase_22 WA -
testcase_23 AC 1 ms
6,944 KB
testcase_24 WA -
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// {{{ Templates
#include <bits/stdc++.h>

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

// }}}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;

    vector<int> num(5, 0);
    string drop;
    for (const char c : s) {
        if (c == 'K') {
            num[0]++;
        } else if (c == 'U') {
            if (num[0] > 0) {
                num[0]--;
                num[1]++;
            } else {
                drop.push_back('U');
            }
        } else if (c == 'R') {
            if (num[1] > 0) {
                num[1]--;
                num[2]++;
            } else {
                drop.push_back('R');
            }
        } else if (c == 'O') {
            if (num[2] > 0) {
                num[2]--;
                num[3]++;
            } else {
                drop.push_back('O');
            }
        } else if (c == 'I') {
            if (num[3] > 0) {
                num[3]--;
                num[4]++;
            } else {
                drop.push_back('I');
            }
        } else if (c == '?') {
            drop.push_back('?');
        }
    }
    int cnt = num[4];

    fill(num.begin(), num.end(), 0);
    for (const char c : drop) {
        if (c == 'K') {
            num[0]++;
        } else if (c == 'U') {
            if (num[0] > 0) {
                num[0]--;
                num[1]++;
            }
        } else if (c == 'R') {
            if (num[1] > 0) {
                num[1]--;
                num[2]++;
            }
        } else if (c == 'O') {
            if (num[2] > 0) {
                num[2]--;
                num[3]++;
            }
        } else if (c == 'I') {
            if (num[3] > 0) {
                num[3]--;
                num[4]++;
            }
        } else if (c == '?') {
            if (num[3] > 0) {
                num[3]--;
                num[4]++;
            } else if (num[2] > 0) {
                num[2]--;
                num[3]++;
            } else if (num[1] > 0) {
                num[1]--;
                num[2]++;
            } else if (num[0] > 0) {
                num[0]--;
                num[1]++;
            } else {
                num[0]++;
            }
        }
    }
    cnt += num[4];
    cout << cnt << endl;

    return 0;
}
0