結果

問題 No.2947 Sing a Song
コンテスト
ユーザー あるふぁ
提出日時 2026-09-23 15:42:03
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 32 ms / 2,000 ms
+ 895µs
コード長 739 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,323 ms
コンパイル使用メモリ 360,716 KB
実行使用メモリ 9,912 KB
最終ジャッジ日時 2026-09-23 15:42:10
合計ジャッジ時間 6,655 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

int main(){
    int N, M = 200010;
    string S, T;
    cin >> N >> S >> T;

    int s = S.size(), t = T.size();
    vector<bool> dp(M, false);
    dp[0] = true;
    for (int i = 0; i < M; i++){
        if (!dp[i]) continue;
        if (i+s < M) dp[i+s] = true;
        if (i+t < M) dp[i+t] = true;
    }

    while (N--){
        int x;
        cin >> x;
        vector<string> ans;
        while (x > 0){
            if (x-s >= 0 && dp[x-s]){
                ans.push_back(S);
                x -= s;
            }
            else{
                ans.push_back(T);
                x -= t;
            }
        }
        for (auto s : ans) cout << s << ' ';
        cout << endl;
    }
}
0