結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー uenokuuenoku
提出日時 2017-08-28 08:43:11
言語 Rust
(1.77.0)
結果
AC  
実行時間 22 ms / 3,000 ms
コード長 1,623 bytes
コンパイル時間 851 ms
コンパイル使用メモリ 175,920 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-24 01:30:10
合計ジャッジ時間 1,719 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 0 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 21 ms
6,940 KB
testcase_08 AC 22 ms
6,944 KB
testcase_09 AC 11 ms
6,944 KB
testcase_10 AC 10 ms
6,940 KB
testcase_11 AC 11 ms
6,944 KB
testcase_12 AC 10 ms
6,940 KB
testcase_13 AC 22 ms
6,940 KB
testcase_14 AC 17 ms
6,940 KB
testcase_15 AC 17 ms
6,940 KB
testcase_16 AC 17 ms
6,940 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 0 ms
6,940 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::cmp::*`
 --> main.rs:4:5
  |
4 | use std::cmp::*;
  |     ^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused import: `std::fmt`
 --> main.rs:5:5
  |
5 | use std::fmt;
  |     ^^^^^^^^

warning: unused variable: `i`
  --> main.rs:27:13
   |
27 |         for i in 0 .. ((n-2)/2){
   |             ^ help: if this is intentional, prefix it with an underscore: `_i`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: variable does not need to be mutable
  --> main.rs:20:13
   |
20 |         let mut mid:usize = ((up+low)/2) as usize;
   |             ----^^^
   |             |
   |             help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` on by default

warning: 4 warnings emitted

ソースコード

diff #

use std::io::*;

use std::str::*;
use std::cmp::*;
use std::fmt;
fn main() {
    let n:usize = read();
    let m:i64 = read();
    let mut a:Vec<i32>=vec![0;n-1];
    let k:i32 = read();
    for i in 0..(n-1){
        let b:i32 = read();
        a[i] = b;
    }
    a.sort();
    let mut up:i32 = (n-1) as i32;
    let mut low:i32 = -1;
    let mut flag:bool = false;
    while up - low > 1{
        let mut mid:usize = ((up+low)/2) as usize;
        let val = k + &a[mid];
        let mut s:usize = 0;
        let mut t:usize = n - 2;
        let mut cnt = 0;

        //println!("#######{} {} {}######",mid,a[mid],cnt);
        for i in 0 .. ((n-2)/2){
            if s == mid {
                s += 1;
            }
            if t == mid{
                t -= 1;
            }
         //   println!("{} {} {} {}",s,t,a[s]+a[t],val);
            if a[s] + a[t] > val {
                s += 1;
                t -= 1;
                cnt += 1;
            }else {
                if s + 1 == mid {
                    s += 1;
                }
                s += 2;
            }
        }

        if cnt < m {
            up = mid as i32;
            flag = true;
        } else {
            low = mid as i32;
        }
    }
    println!("{}",(if flag { a[up as usize]}else{-1}));
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().unwrap_or_else(|_| panic!("Faild to parse {}", s))
}


0