結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー phsplsphspls
提出日時 2022-10-18 21:01:02
言語 Rust
(1.77.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,660 bytes
コンパイル時間 4,111 ms
コンパイル使用メモリ 153,648 KB
実行使用メモリ 38,560 KB
最終ジャッジ日時 2023-09-11 13:16:17
合計ジャッジ時間 7,702 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 65 ms
38,384 KB
testcase_17 AC 65 ms
38,492 KB
testcase_18 AC 64 ms
38,544 KB
testcase_19 AC 63 ms
38,552 KB
testcase_20 AC 63 ms
38,560 KB
testcase_21 AC 64 ms
38,552 KB
testcase_22 AC 5 ms
4,384 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 53 ms
31,184 KB
testcase_25 AC 4 ms
4,376 KB
testcase_26 AC 63 ms
38,520 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `j`
  --> Main.rs:50:13
   |
50 |         for j in 0..c[i] {
   |             ^ help: if this is intentional, prefix it with an underscore: `_j`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

diff #

fn main() {
    let mut temp = String::new();
    std::io::stdin().read_line(&mut temp).ok();
    let temp: Vec<&str> = temp.trim().split_whitespace().collect();
    let n = temp[0].parse::<usize>().unwrap();
    let k = temp[1].to_string();
    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);
    let maxval = (0..10).rev().map(|i| i.to_string().repeat(c[i])).collect::<Vec<_>>().join("");
    if maxval.len() < k.len() || k >= maxval {
        println!("-1");
        return;
    }
    if k.len() < n {
        println!("{}", (0..10).map(|i| i.to_string().repeat(c[i])).collect::<Vec<_>>().join(""));
        return;
    }
    let mut idx = 0usize;
    let kvals = k.chars().map(|c| c as usize - '0' as usize).collect::<Vec<_>>();
    while idx < k.len() && c[kvals[idx]] > 0 {
        c[kvals[idx]] -= 1;
        idx += 1;
    }
    if idx == k.len() {
        idx -= 1;
        c[kvals[idx]] += 1;
    }
    let mut result = (0..idx).map(|i| kvals[i]).collect::<Vec<_>>();
    loop {
        let mut flg = false;
        for i in kvals[result.len()]+1..10 {
            if c[i] > 0 {
                result.push(i);
                c[i] -= 1;
                flg = true;
                break;
            }
        }
        if flg {
            break;
        } else {
            c[result.pop().unwrap()] += 1;
        }
    }
    for i in 0..10 {
        for j in 0..c[i] {
            result.push(i);
        }
    }
    println!("{}", result.into_iter().map(|i| i.to_string()).collect::<Vec<_>>().join(""));
}
0