結果

問題 No.2947 Sing a Song
ユーザー GOTKAKO
提出日時 2024-10-26 14:50:21
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 792 bytes
コンパイル時間 2,230 ms
コンパイル使用メモリ 194,652 KB
最終ジャッジ日時 2025-02-25 00:23:01
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

    int N; cin >> N;
    string s,t; cin >> s >> t;
    int n = s.size(),m = t.size();
    vector<int> dp(200001,-1001001001);
    dp.at(0) = 0;
    for(int i=1; i<=200000; i++){
        if(i >= n) dp.at(i) = dp.at(i-n)+1;
        if(i >= m) dp.at(i) = max(dp.at(i),dp.at(i-m));
    }
    while(N--){
        int a; cin >> a;
        int Ss = dp.at(a);
        bool first = true;
        a -= Ss*n; a /= m;
        while(Ss--){
            if(!first) cout << " "; 
            first = false; 
            cout << s;
        }
        while(a--){
            if(!first) cout << " ";
            first = false; 
            cout << t;
        }
        cout << "\n";
    }
}
0