結果
問題 | No.1630 Sorting Integers (Greater than K) |
ユーザー | fukafukatani |
提出日時 | 2021-07-31 11:08:35 |
言語 | Rust (1.77.0 + proconio) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,658 bytes |
コンパイル時間 | 12,627 ms |
コンパイル使用メモリ | 404,060 KB |
実行使用メモリ | 15,220 KB |
最終ジャッジ日時 | 2024-09-16 09:16:50 |
合計ジャッジ時間 | 14,302 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | WA | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | AC | 45 ms
15,076 KB |
testcase_19 | RE | - |
testcase_20 | AC | 46 ms
15,072 KB |
testcase_21 | AC | 46 ms
15,080 KB |
testcase_22 | RE | - |
testcase_23 | AC | 3 ms
5,376 KB |
testcase_24 | RE | - |
testcase_25 | AC | 12 ms
11,108 KB |
testcase_26 | AC | 42 ms
11,108 KB |
コンパイルメッセージ
warning: unreachable statement --> src/main.rs:100:13 | 99 | unreachable!(); | -------------- any code following this expression is unreachable 100 | / for j in (0..i).rev() { 101 | | c[answers[j] - 1] += 1; 102 | | answers.pop(); 103 | | for k in kp1[j]..9 { ... | 123 | | } 124 | | } | |_____________^ unreachable statement | = note: `#[warn(unreachable_code)]` on by default warning: unused variable: `i` --> src/main.rs:78:18 | 78 | 'outer: for (i, &num) in kp1.iter().enumerate() { | ^ help: if this is intentional, prefix it with an underscore: `_i` | = note: `#[warn(unused_variables)]` on by default
ソースコード
#![allow(unused_imports)] use std::cmp::*; use std::collections::*; use std::io::Write; use std::ops::Bound::*; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn main() { let v = read_vec::<String>(); let (n, k) = (v[0].parse::<usize>().unwrap(), v[1].clone()); let mut c = read_vec::<usize>(); if k.len() > n { println!("-1"); return; } if k.len() < n { for i in 0..n { for _ in 0..c[i] { print!("{}", i + 1); } } println!(""); return; } let mut k = k .chars() .map(|x| x.to_digit(10).unwrap() as usize) .collect::<Vec<_>>(); k.reverse(); let mut kp1 = vec![]; let mut carry = k[0] == 9; if carry { kp1.push(0); } else { kp1.push(k[0] + 1); } for i in 1..n { carry = k[i] == 9 && carry; if carry { kp1.push(0); } else { kp1.push(k[i]); } } if carry { println!("-1"); return; } kp1.reverse(); let mut kp1_count = vec![0; 10]; for &num in &kp1 { kp1_count[num] += 1; } if (0..9).all(|i| kp1_count[i + 1] == c[i]) { for num in kp1 { print!("{}", num); } println!(""); return; } let mut answers = vec![]; let mut overed = false; 'outer: for (i, &num) in kp1.iter().enumerate() { if overed { for j in 0..9 { if c[j] >= 1 { c[j] -= 1; answers.push(j + 1); continue 'outer; } } } else { let left = if num > 0 { num - 1 } else { 0 }; for j in left..9 { if c[j] >= 1 { c[j] -= 1; answers.push(j + 1); if j + 1 > num { overed = true; } continue 'outer; } } unreachable!(); for j in (0..i).rev() { c[answers[j] - 1] += 1; answers.pop(); for k in kp1[j]..9 { debug!(c); if c[k] > 0 { answers.push(k + 1); c[k] -= 1; while c.iter().any(|&x| c[x] > 0) { for jj in 0..9 { if c[jj] >= 1 { c[jj] -= 1; answers.push(jj + 1); break; } } } for ans in answers { print!("{}", ans); } println!(""); return; } } } println!("-1"); return; } } for ans in answers { print!("{}", ans); } println!(""); } fn read<T: std::str::FromStr>() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() }