結果

問題 No.3320 yiwiwiy
コンテスト
ユーザー みうね
提出日時 2025-10-06 09:59:00
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,641 bytes
コンパイル時間 2,797 ms
コンパイル使用メモリ 286,220 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-10-31 18:53:22
合計ジャッジ時間 6,610 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other WA * 73
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

// 部分列として "yiwiy" の出現数をカウント
ll count_yiwiy(const string &s) {
    vector<ll> dp(6, 0);
    // dp[k]: 最初のk文字 "yiwiy"[0..k-1] を作る部分列数
    string t = "yiwiy";
    dp[0] = 1;
    for (char c : s) {
        for (int k = 4; k >= 0; k--) {
            if (c == t[k]) dp[k + 1] += dp[k];
        }
    }
    return dp[5];
}

// 部分列として "iwiwi" の出現数をカウント
ll count_iwiwi(const string &s) {
    vector<ll> dp(6, 0);
    string t = "iwiwi";
    dp[0] = 1;
    for (char c : s) {
        for (int k = 4; k >= 0; k--) {
            if (c == t[k]) dp[k + 1] += dp[k];
        }
    }
    return dp[5];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll Y, I, W, A, B;
    cin >> Y >> I >> W >> A >> B;

    vector<string> candidates;

    // yiwiy優先配置
    {
        string s = string(Y/2, 'y') + string(I/2, 'i') + string(W, 'w') + string(I - I/2, 'i') + string(Y - Y/2, 'y');
        candidates.push_back(s);
    }
    // iwiwi優先配置
    {
        string s = "";
        int total = Y + I + W;
        for (int j = 0; j < total; j++) {
            if (I > 0) { s += 'i'; I--; }
            if (W > 0) { s += 'w'; W--; }
        }
        s += string(Y, 'y');
        candidates.push_back(s);
    }

    ll best_val = -1;
    string best_s;

    for (auto &s : candidates) {
        ll val = A * count_yiwiy(s) + B * count_iwiwi(s);
        if (val > best_val) {
            best_val = val;
            best_s = s;
        }
    }

    cout << best_s << "\n";
}
0