結果

問題 No.2142 Segment Zero
ユーザー akakimidoriakakimidori
提出日時 2022-12-02 23:29:30
言語 Rust
(1.77.0 + proconio)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 4,785 bytes
コンパイル時間 13,496 ms
コンパイル使用メモリ 379,504 KB
実行使用メモリ 9,732 KB
最終ジャッジ日時 2024-10-10 01:59:33
合計ジャッジ時間 14,260 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 27 ms
9,732 KB
testcase_02 AC 1 ms
6,820 KB
testcase_03 AC 61 ms
9,656 KB
testcase_04 AC 59 ms
9,676 KB
testcase_05 AC 59 ms
9,624 KB
testcase_06 AC 1 ms
6,816 KB
testcase_07 AC 58 ms
9,716 KB
testcase_08 AC 28 ms
9,704 KB
testcase_09 AC 50 ms
9,704 KB
testcase_10 AC 28 ms
9,604 KB
testcase_11 AC 28 ms
9,516 KB
testcase_12 AC 27 ms
9,700 KB
testcase_13 AC 28 ms
9,600 KB
testcase_14 AC 28 ms
9,524 KB
testcase_15 AC 28 ms
9,712 KB
testcase_16 AC 28 ms
9,588 KB
testcase_17 AC 24 ms
8,184 KB
testcase_18 AC 15 ms
6,816 KB
testcase_19 AC 12 ms
6,816 KB
testcase_20 AC 17 ms
6,820 KB
testcase_21 AC 36 ms
6,820 KB
testcase_22 AC 22 ms
7,456 KB
testcase_23 AC 7 ms
6,820 KB
testcase_24 AC 10 ms
6,816 KB
testcase_25 AC 21 ms
6,816 KB
testcase_26 AC 33 ms
7,276 KB
testcase_27 AC 43 ms
7,572 KB
testcase_28 AC 13 ms
6,816 KB
testcase_29 AC 17 ms
6,816 KB
testcase_30 AC 21 ms
7,468 KB
testcase_31 AC 44 ms
7,264 KB
testcase_32 AC 15 ms
6,820 KB
testcase_33 AC 5 ms
6,816 KB
testcase_34 AC 19 ms
6,816 KB
testcase_35 AC 27 ms
9,532 KB
testcase_36 AC 8 ms
6,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    input!(n: usize, k: usize);
    let mut a = vec![0; n + 1];
    for i in 1..=n {
        a[i] = i + a[i - 1];
    }
    let mut ans = 2;
    for l in 0..n {
        let t = a[l] + a[n] - k;
        let x = a.lower_bound(&t);
        if x < a.len() && a[x] == t {
            ans = 1;
        }
    }
    println!("{}", ans);
}

// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[macro_export]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[macro_export]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[macro_export]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------
// ---------- begin super slice ----------
pub trait SuperSlice {
    type Item;
    fn lower_bound(&self, key: &Self::Item) -> usize
    where
        Self::Item: Ord;
    fn lower_bound_by<F>(&self, f: F) -> usize
    where
        F: FnMut(&Self::Item) -> std::cmp::Ordering;
    fn lower_bound_by_key<K, F>(&self, key: &K, f: F) -> usize
    where
        K: Ord,
        F: FnMut(&Self::Item) -> K;
    fn upper_bound(&self, key: &Self::Item) -> usize
    where
        Self::Item: Ord;
    fn upper_bound_by<F>(&self, f: F) -> usize
    where
        F: FnMut(&Self::Item) -> std::cmp::Ordering;
    fn upper_bound_by_key<K, F>(&self, key: &K, f: F) -> usize
    where
        K: Ord,
        F: FnMut(&Self::Item) -> K;
    fn next_permutation(&mut self) -> bool
    where
        Self::Item: Ord;
    fn next_permutation_by<F>(&mut self, f: F) -> bool
    where
        F: FnMut(&Self::Item, &Self::Item) -> std::cmp::Ordering;
    fn prev_permutation(&mut self) -> bool
    where
        Self::Item: Ord;
}

impl<T> SuperSlice for [T] {
    type Item = T;
    fn lower_bound(&self, key: &Self::Item) -> usize
    where
        T: Ord,
    {
        self.lower_bound_by(|p| p.cmp(key))
    }
    fn lower_bound_by<F>(&self, mut f: F) -> usize
    where
        F: FnMut(&Self::Item) -> std::cmp::Ordering,
    {
        self.binary_search_by(|p| f(p).then(std::cmp::Ordering::Greater))
            .unwrap_err()
    }
    fn lower_bound_by_key<K, F>(&self, key: &K, mut f: F) -> usize
    where
        K: Ord,
        F: FnMut(&Self::Item) -> K,
    {
        self.lower_bound_by(|p| f(p).cmp(key))
    }
    fn upper_bound(&self, key: &Self::Item) -> usize
    where
        T: Ord,
    {
        self.upper_bound_by(|p| p.cmp(key))
    }
    fn upper_bound_by<F>(&self, mut f: F) -> usize
    where
        F: FnMut(&Self::Item) -> std::cmp::Ordering,
    {
        self.binary_search_by(|p| f(p).then(std::cmp::Ordering::Less))
            .unwrap_err()
    }
    fn upper_bound_by_key<K, F>(&self, key: &K, mut f: F) -> usize
    where
        K: Ord,
        F: FnMut(&Self::Item) -> K,
    {
        self.upper_bound_by(|p| f(p).cmp(key))
    }
    fn next_permutation(&mut self) -> bool
    where
        T: Ord,
    {
        self.next_permutation_by(|a, b| a.cmp(b))
    }
    fn next_permutation_by<F>(&mut self, mut f: F) -> bool
    where
        F: FnMut(&Self::Item, &Self::Item) -> std::cmp::Ordering,
    {
        use std::cmp::Ordering::*;
        if let Some(x) = self.windows(2).rposition(|a| f(&a[0], &a[1]) == Less) {
            let y = self.iter().rposition(|b| f(&self[x], b) == Less).unwrap();
            self.swap(x, y);
            self[(x + 1)..].reverse();
            true
        } else {
            self.reverse();
            false
        }
    }
    fn prev_permutation(&mut self) -> bool
    where
        T: Ord,
    {
        self.next_permutation_by(|a, b| a.cmp(b).reverse())
    }
}
// ---------- end super slice ----------

0