結果

問題 No.723 2つの数の和
ユーザー sinosino
提出日時 2021-04-08 11:21:13
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,354 bytes
コンパイル時間 936 ms
コンパイル使用メモリ 150,440 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 19:57:46
合計ジャッジ時間 5,960 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_end().to_owned()
}

fn main() {
    let (_n, x) = read!(usize, usize);
    let mut a = read!([usize]);
    a.sort();

    let mut cnt = 0;
    let mut r_min = 0;
    for l in 0..a.len() {
        for r in r_min..a.len() {
            match (a[l] + a[r]).cmp(&x) {
                std::cmp::Ordering::Equal if a[l] + a[l] == x => {
                    cnt += 1;
                }
                std::cmp::Ordering::Equal => {
                    cnt += 2;
                }
                std::cmp::Ordering::Greater => {
                    r_min = r;
                    break;
                }
                _ => {}
            }
        }
    }
    println!("{}", cnt);
}
0