結果
問題 | No.270 next_permutation (1) |
ユーザー | koba-e964 |
提出日時 | 2017-01-10 17:28:08 |
言語 | Rust (1.77.0 + proconio) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,078 bytes |
コンパイル時間 | 16,389 ms |
コンパイル使用メモリ | 383,644 KB |
実行使用メモリ | 13,636 KB |
最終ジャッジ日時 | 2024-12-18 00:25:12 |
合計ジャッジ時間 | 29,927 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
13,636 KB |
testcase_01 | AC | 2 ms
10,276 KB |
testcase_02 | AC | 2 ms
10,272 KB |
testcase_03 | AC | 1 ms
6,816 KB |
testcase_04 | AC | 3 ms
6,816 KB |
testcase_05 | AC | 3 ms
6,816 KB |
testcase_06 | AC | 3 ms
6,816 KB |
testcase_07 | AC | 2 ms
6,820 KB |
testcase_08 | AC | 10 ms
6,816 KB |
testcase_09 | AC | 242 ms
6,816 KB |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | TLE | - |
testcase_13 | AC | 1,761 ms
6,820 KB |
testcase_14 | TLE | - |
コンパイルメッセージ
warning: variable does not need to be mutable --> src/main.rs:38:9 | 38 | let mut n = v.len(); | ----^ | | | help: remove this `mut` | = note: `#[warn(unused_mut)]` on by default warning: unused variable: `ret` --> src/main.rs:73:13 | 73 | let ret = next_permutation(&mut p); | ^^^ help: if this is intentional, prefix it with an underscore: `_ret` | = note: `#[warn(unused_variables)]` on by default
ソースコード
#[allow(unused_imports)] use std::cmp::*; #[allow(unused_imports)] use std::collections::*; use std::io::*; #[allow(dead_code)] fn getline() -> String { let mut ret = String::new(); std::io::stdin().read_line(&mut ret).ok(); return ret; } fn get_word() -> String { let mut stdin = std::io::stdin(); let mut u8b: [u8; 1] = [0]; loop { let mut buf: Vec<u8> = Vec::with_capacity(16); loop { let res = stdin.read(&mut u8b); if res.is_err() || res.ok().unwrap() == 0 || u8b[0] <= ' ' as u8 { break; } else { buf.push(u8b[0]); } } if buf.len() >= 1 { let ret = std::string::String::from_utf8(buf).unwrap(); return ret; } } } fn parse<T: std::str::FromStr>(s: &str) -> T { s.parse::<T>().ok().unwrap() } #[allow(dead_code)] fn get<T: std::str::FromStr>() -> T { parse(&get_word()) } fn next_permutation<T: Ord>(v: &mut [T]) -> usize { let mut tail_dec: usize = 1; let mut n = v.len(); while tail_dec < n { if v[n - tail_dec - 1] > v[n - tail_dec] { tail_dec += 1; } else { break; } } // v[n - tail_dec .. n] is strictly decreasing if tail_dec < n { let x = n - tail_dec - 1; let mut y = n; { let pivot = &v[x]; for i in (n - tail_dec .. n).rev() { if v[i] > *pivot { y = i; break; } } assert!(y < n); } v.swap(x, y); } v[n - tail_dec .. n].sort(); return max(n - tail_dec, 1) - 1; } fn main() { let n: usize = get(); let k: usize = get(); let mut p: Vec<i64> = (0 .. n).map(|_| get()).collect(); let b: Vec<i64> = (0 .. n).map(|_| get()).collect(); let mut tot: i64 = 0; for _ in 0 .. k { let ret = next_permutation(&mut p); for i in 0 .. n { tot += (p[i] - b[i]).abs(); } } println!("{}", tot); }