結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー phsplsphspls
提出日時 2022-10-11 11:13:31
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,659 bytes
コンパイル時間 4,063 ms
コンパイル使用メモリ 146,868 KB
実行使用メモリ 38,672 KB
最終ジャッジ日時 2023-09-07 12:37:27
合計ジャッジ時間 8,147 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

fn main() {
    let mut nk = String::new();
    std::io::stdin().read_line(&mut nk).ok();
    let nk: Vec<&str> = nk.trim().split_whitespace().collect();
    let n = nk[0].parse::<usize>().unwrap();
    let k = nk[1].chars().map(|c| c as usize - '0' as usize).collect::<Vec<_>>();
    let mut c = String::new();
    std::io::stdin().read_line(&mut c).ok();
    let mut c: Vec<usize> = c.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    c.insert(0, 0);
    if k.len() < n {
        println!("{}", (0..10).map(|i| i.to_string().repeat(c[i])).collect::<Vec<_>>().join(""));
        return;
    }
    let maxval = (0..10).rev().map(|i| i.to_string().repeat(c[i])).collect::<Vec<_>>().join("");
    if k.len() > n || k.iter().map(|&c| c.to_string()).collect::<Vec<_>>().join("") >= maxval {
        println!("-1");
        return;
    }
    let mut result = vec![];
    let mut idx = 0usize;
    while idx < n && c[k[idx]] > 0 {
        result.push(k[idx]);
        c[k[idx]] -= 1;
        idx += 1;
    }
    if idx == n {
        idx -= 1;
        c[result.pop().unwrap()] += 1;
    }
    loop {
        let mut flg = false;
        for i in k[idx]+1..10 {
            if c[i] > 0 {
                result.push(c[i]);
                idx += 1;
                c[i] -= 1;
                flg = true;
                break;
            }
        }
        if flg {
            break;
        } else {
            c[result.pop().unwrap()] += 1;
            idx -= 1;
        }
    }
    for i in 0..10 {
        for _ in 0..c[i] { result.push(i); }
    }
    println!("{}", result.iter().map(|v| v.to_string()).collect::<Vec<_>>().join(""));
}
0