結果

問題 No.9 モンスターのレベル上げ
ユーザー tsubu_taiyakitsubu_taiyaki
提出日時 2017-02-06 06:07:45
言語 Rust
(1.59.0)
結果
AC  
実行時間 540 ms / 5,000 ms
コード長 2,040 bytes
コンパイル時間 3,600 ms
使用メモリ 2,216 KB
最終ジャッジ日時 2023-01-21 16:24:48
合計ジャッジ時間 8,321 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
2,068 KB
testcase_01 AC 1 ms
1,992 KB
testcase_02 AC 508 ms
2,120 KB
testcase_03 AC 402 ms
2,112 KB
testcase_04 AC 216 ms
2,012 KB
testcase_05 AC 139 ms
2,176 KB
testcase_06 AC 49 ms
2,080 KB
testcase_07 AC 2 ms
1,980 KB
testcase_08 AC 65 ms
1,912 KB
testcase_09 AC 492 ms
2,128 KB
testcase_10 AC 1 ms
1,964 KB
testcase_11 AC 471 ms
2,112 KB
testcase_12 AC 236 ms
2,172 KB
testcase_13 AC 540 ms
2,216 KB
testcase_14 AC 492 ms
2,068 KB
testcase_15 AC 452 ms
2,080 KB
testcase_16 AC 9 ms
1,924 KB
testcase_17 AC 292 ms
2,120 KB
testcase_18 AC 246 ms
2,088 KB
testcase_19 AC 6 ms
2,036 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: trait objects without an explicit `dyn` are deprecated
  --> Main.rs:10:21
   |
10 |     tokens: &'a mut Iterator<Item = String>,
   |                     ^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(bare_trait_objects)]` on by default
   = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
   = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
   |
10 -     tokens: &'a mut Iterator<Item = String>,
10 +     tokens: &'a mut dyn Iterator<Item = String>,
   | 

warning: trait objects without an explicit `dyn` are deprecated
  --> Main.rs:14:23
   |
14 |     fn new(i: &'a mut Iterator<Item = String>) -> Self {
   |                       ^^^^^^^^^^^^^^^^^^^^^^^
   |
   = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
   = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
   |
14 -     fn new(i: &'a mut Iterator<Item = String>) -> Self {
14 +     fn new(i: &'a mut dyn Iterator<Item = String>) -> Self {
   | 

warning: 2 warnings emitted

ソースコード

diff #

#![allow(unused_imports)]

use std::io::{self, BufRead};
use std::str::FromStr;
use std::collections::*;
use std::cmp::*;

#[allow(dead_code)]
struct Parser<'a> {
    tokens: &'a mut Iterator<Item = String>,
}
#[allow(dead_code)]
impl<'a> Parser<'a> {
    fn new(i: &'a mut Iterator<Item = String>) -> Self {
        Parser {tokens: i}
    }
    fn take<T: FromStr>(&mut self) -> T {
        match self.tokens.next().expect("empty iterator").parse() {
            Ok(x) => x,
            Err(_) => panic!()
        }
    }

    fn take_some<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        self.tokens.take(n).map(|s| match s.parse() { Ok(x) => x, Err(_) => panic!() } ).collect()
    }
}

//sieve[k] is true if k is a prime
//[0, n)
#[allow(dead_code)]
fn sieve_of_eratosthenes(n: u64) -> Vec<bool> {
    let mut v = vec![true; n as usize];
    v[0] = false;
    v[1] = false;
    for i in 2..n {
        if !v[i as usize] {
            continue;
        }
        let mut j = 2*i;
        while j < n {
            v[j as usize] = false;
            j += i;
        }
    }
    v
}

fn main() {
    let stdin = io::stdin();
    let mut tokens = stdin.lock().lines().filter_map(|x| x.ok()).flat_map(|x| x.split_whitespace().map(|s| s.to_owned()).collect::<Vec<String>>());
    let mut parser = Parser::new(&mut tokens);

    let n: usize = parser.take();
    let a: Vec<i32> = parser.take_some(n);
    let b: Vec<i32> = parser.take_some(n);

    let a: BTreeSet<_> = a.into_iter().zip(0..n).map(|x| (x.0, 0, x.1)).collect();
    let b: Vec<i32> = b.into_iter().map(|x| x/2).collect();
    let mut ans = n;
    for i in 0..n {
        let mut ai = a.clone();
        for j in 0..n {
            let idx = (i+j) % n;
            let x = (*ai.iter().nth(0).unwrap()).clone();
            ai.remove(&x);
            ai.insert((x.0 + b[idx], x.1+1, x.2));
        }
        let mut ansi = 0;
        for ite in ai.into_iter() {
            ansi = max(ansi, ite.1);
        }
        ans = min(ans, ansi);
    }
    println!("{}", ans);
}


0