結果

問題 No.2947 Sing a Song
ユーザー naut3
提出日時 2024-10-26 11:00:03
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 1,401 bytes
コンパイル時間 12,662 ms
コンパイル使用メモリ 407,748 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-26 11:00:20
合計ジャッジ時間 16,412 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(non_snake_case, unused_must_use, unused_imports)]
use std::io::{self, prelude::*};

fn main() {
    let (stdin, stdout) = (io::read_to_string(io::stdin()).unwrap(), io::stdout());
    let (mut stdin, mut buffer) = (stdin.split_whitespace(), io::BufWriter::new(stdout.lock()));
    macro_rules! input {
        ($t: ty, $n: expr) => {
            (0..$n).map(|_| input!($t)).collect::<Vec<_>>()
        };
        ($t: ty) => {
            stdin.next().unwrap().parse::<$t>().unwrap()
        };
    }

    let N = input!(usize);
    let S = input!(String);
    let T = input!(String);

    let A = input!(usize, N);

    let mut dp = vec![isize::MIN; 200_010];
    dp[0] = 0;

    for i in 0..200_010 {
        if i + S.len() < 200_010 {
            dp[i + S.len()] = std::cmp::max(dp[i + S.len()], dp[i] + 1);
        }

        if i + T.len() < 200_010 {
            dp[i + T.len()] = std::cmp::max(dp[i + T.len()], dp[i]);
        }
    }

    for a in A {
        let mut ans = vec![];

        for _ in 0..dp[a] {
            ans.push(S.clone());
        }

        let t = (a - S.len() * dp[a] as usize) / T.len();

        for _ in 0..t {
            ans.push(T.clone());
        }

        writeln!(
            buffer,
            "{}",
            ans.iter()
                .map(|x| x.to_string())
                .collect::<Vec<_>>()
                .join(" ")
        );
    }
}
0