結果

問題 No.1722 [Cherry 3rd Tune C] In my way
ユーザー StrorkisStrorkis
提出日時 2021-10-29 22:06:11
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 3,121 bytes
コンパイル時間 862 ms
コンパイル使用メモリ 174,144 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-16 14:57:25
合計ジャッジ時間 1,622 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
5,248 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

pub mod io {
    pub fn scan<R: std::io::BufRead>(r: &mut R) -> Vec<u8> {
        let mut res = Vec::new();
        loop {
            let buf = match r.fill_buf() {
                Ok(buf) => buf,
                Err(e) if e.kind() == std::io::ErrorKind::Interrupted => continue,
                Err(e) => panic!("{}", e), 
            };
            let (done, used, buf) = match buf.iter().position(u8::is_ascii_whitespace) {
                Some(i) => (i > 0 || res.len() > 0, i + 1, &buf[..i]),
                None => (buf.is_empty(), buf.len(), buf),
            };
            res.extend_from_slice(buf);
            r.consume(used);
            if done { return res; }
        }
    }

    #[macro_export]
    macro_rules! scan {
        ($r:expr, [$t:tt; $n:expr]) => ((0..$n).map(|_| scan!($r, $t)).collect::<Vec<_>>());
        ($r:expr, [$t:tt]) => (scan!($r, [$t; scan!($r, usize)]));
        ($r:expr, ($($t:tt),*)) => (($(scan!($r, $t)),*));
        ($r:expr, Usize1) => (scan!($r, usize) - 1);
        ($r:expr, String) => (String::from_utf8(scan!($r, Bytes)).unwrap());
        ($r:expr, Bytes) => (io::scan($r));
        ($r:expr, $t:ty) => (scan!($r, String).parse::<$t>().unwrap());
    }

    #[macro_export]
    macro_rules! input {
        ($r:expr, $($($v:ident)* : $t:tt),* $(,)?) => {
            $(let $($v)* = scan!($r, $t);)*
        };
    }
}

pub mod binary_search {
    pub trait BinarySearch<T> {
        fn lower_bound(&self, x: &T) -> usize;
        fn upper_bound(&self, x: &T) -> usize;
    }

    impl<T: PartialOrd> BinarySearch<T> for [T] {
        fn lower_bound(&self, x: &T) -> usize {
            let mut left = 0;
            let mut right = self.len();
            while left < right {
                let mid = (left + right) / 2;
                if unsafe { self.get_unchecked(mid) } < x {
                    left = mid + 1;
                } else {
                    right = mid;
                }
            }
            left
        }

        fn upper_bound(&self, x: &T) -> usize {
            let mut left = 0;
            let mut right = self.len();
            while left < right {
                let mid = (left + right) / 2;
                if unsafe { self.get_unchecked(mid) } <= x {
                    left = mid + 1;
                } else {
                    right = mid;
                }
            }
            left
        }
    }
}

use binary_search::BinarySearch;

const INF: u64 = 1 << 30;

fn run<R: std::io::BufRead, W: std::io::Write>(reader: &mut R, writer: &mut W) {
    input! {
        reader,
        n: usize, m: usize,
        x: [u64; n],
        mut y: [u64; m],
    }
    y.push(INF);

    for x in x {
        let i = y.lower_bound(&x);
        if i == m {
            writeln!(writer, "Infinity").ok();
        } else {
            writeln!(writer, "{}", y[i] - x).ok();
        }
    }
}

fn main() {
    let (stdin, stdout) = (std::io::stdin(), std::io::stdout());
    let ref mut reader = std::io::BufReader::new(stdin.lock());
    let ref mut writer = std::io::BufWriter::new(stdout.lock());
    run(reader, writer);
}
0