結果

問題 No.2194 兄弟の掛け引き
ユーザー myu2myu2
提出日時 2023-02-25 09:56:13
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 2,399 bytes
コンパイル時間 717 ms
コンパイル使用メモリ 154,492 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-11 11:09:13
合計ジャッジ時間 1,723 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,356 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports, unused_macros)]
use std::cmp::*;
use std::collections::*;
use std::io::Read;
use x_macros::*;

fn main() {
    // input
    input! {
        a: i32,
        b: i32,
        c: i32,
    }
    // main
    let mut ans = vec![];
    if c / a > 0 && c % a == 0 && c <= b {
        ans.push(c / a);
    }
    if (c + b) / a > 0 && (c + b) % a == 0 {
        ans.push((c + b) / a);
    }
    if ans.len() == 0 {
        ans.push(-1);
    }
    // output
    for x in ans {
        println!("{}", x);
    }
}

// ----------------------------------------------------------------
#[macro_use]
pub mod x_macros {

    #[macro_export]
    macro_rules! input {
        ($($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)*}
        };
    }

    #[macro_export]
    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)*}
        };
    }

    #[macro_export]
    macro_rules! read_value {
        ($next:expr, [ $t:tt ; $len:expr ]) => {
            (0..$len)
                .map(|_| read_value!($next, $t))
                .collect::<Vec<_>>()
        };
        ($next:expr, $t:ty) => {
            $next().parse::<$t>().expect("Parse error")
        };
    }
}

// input (to parse query)
fn get_word() -> String {
    let stdin = std::io::stdin();
    let mut stdin = stdin.lock();
    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.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T {
    get_word().parse().ok().unwrap()
}
0