結果

問題 No.846 メダル
ユーザー kaito_tateyamakaito_tateyama
提出日時 2019-07-05 22:28:27
言語 Rust
(1.72.1)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,883 bytes
コンパイル時間 1,281 ms
コンパイル使用メモリ 78,996 KB
最終ジャッジ日時 2023-07-28 23:49:19
合計ジャッジ時間 2,061 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
warning: unnecessary parentheses around block return value
   --> Main.rs:105:70
    |
105 |         let tdown = vig::S::binary_search(&vec![down,up], &|i: u64|{ ((i+p-1)/p == a && (i+q-1)/q == a+b && (i+r-1)/r==a+b+c)} );
    |                                                                      ^                                                      ^
    |
    = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
    |
105 -         let tdown = vig::S::binary_search(&vec![down,up], &|i: u64|{ ((i+p-1)/p == a && (i+q-1)/q == a+b && (i+r-1)/r==a+b+c)} );
105 +         let tdown = vig::S::binary_search(&vec![down,up], &|i: u64|{ (i+p-1)/p == a && (i+q-1)/q == a+b && (i+r-1)/r==a+b+c} );
    |

error[E0782]: trait objects must include the `dyn` keyword
  --> Main.rs:67:37
   |
67 |         fn binary_search(&self, f: &Fn(u64)->bool) -> u64;
   |                                     ^^^^^^^^^^^^^
   |
help: add `dyn` keyword before this trait
   |
67 |         fn binary_search(&self, f: &dyn Fn(u64)->bool) -> u64;
   |                                     +++

error[E0782]: trait objects must include the `dyn` keyword
  --> Main.rs:70:37
   |
70 |         fn binary_search(&self, f: &Fn(u64)->bool) -> u64 {
   |                                     ^^^^^^^^^^^^^
   |
help: add `dyn` keyword before this trait
   |
70 |         fn binary_search(&self, f: &dyn Fn(u64)->bool) -> u64 {
   |                                     +++

error: aborting due to 2 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0782`.

ソースコード

diff #

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
mod vig {
    pub trait S {
        fn binary_search(&self, f: &Fn(u64)->bool) -> u64;
    }
    impl S for Vec<u64> {
        fn binary_search(&self, f: &Fn(u64)->bool) -> u64 {
            let mut ng: u64 = self[0];
            let mut ok: u64 = self[1];
            loop {
                if ok as i64 - ng as i64 <= 1 {
                    break;
                }
                let mid = (ok + ng) / 2;
                if f(mid) {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            ok
        }
    }
}

fn main() {
    input!{
        p:u64,
        q:u64,
        r:u64,
        a:u64,
        b:u64,
        c:u64,
    }
    let down = std::cmp::max(p*(a-1), std::cmp::max(q*(a+b-1), r*(a+b+c-1)));
    let up = std::cmp::min(p*a, std::cmp::min(q*(a+b), r*(a+b+c)));
    // let mut tdown = down;
    // println!("{} {} {}", p*a, q*b, r*c);
    // println!("{}", vec![down..up]);
    
    if down < up {
        let tdown = vig::S::binary_search(&vec![down,up], &|i: u64|{ ((i+p-1)/p == a && (i+q-1)/q == a+b && (i+r-1)/r==a+b+c)} );
        println!("{} {}",tdown, up);
    }else{
        println!("-1");
    }
}
0