結果

問題 No.723 2つの数の和
ユーザー hatoohatoo
提出日時 2018-08-06 12:05:49
言語 Rust
(1.77.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 3,256 bytes
コンパイル時間 2,194 ms
コンパイル使用メモリ 199,360 KB
実行使用メモリ 6,244 KB
最終ジャッジ日時 2023-10-19 22:08:38
合計ジャッジ時間 3,357 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 10 ms
4,348 KB
testcase_04 AC 17 ms
6,188 KB
testcase_05 AC 13 ms
4,348 KB
testcase_06 AC 15 ms
6,156 KB
testcase_07 AC 7 ms
4,348 KB
testcase_08 AC 8 ms
4,348 KB
testcase_09 AC 14 ms
6,208 KB
testcase_10 AC 7 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 8 ms
4,348 KB
testcase_13 AC 15 ms
6,236 KB
testcase_14 AC 4 ms
4,348 KB
testcase_15 AC 7 ms
4,348 KB
testcase_16 AC 10 ms
4,348 KB
testcase_17 AC 12 ms
4,348 KB
testcase_18 AC 6 ms
4,348 KB
testcase_19 AC 9 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 16 ms
6,244 KB
testcase_24 AC 5 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `n`
  --> Main.rs:63:10
   |
63 |     let (n, x) = get!(usize, u64);
   |          ^ help: if this is intentional, prefix it with an underscore: `_n`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

diff #

#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( $ t : ty ;; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ;; ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
fn solve() {
    let (n, x) = get!(usize, u64);
    let aa = get!(u64;;);

    let mut set = HashMap::new();

    for &a in &aa {
        *set.entry(a).or_insert(0) += 1;
    }

    let ans = aa
        .into_iter()
        .map(|a| {
            if x >= a {
                *set.get(&(x - a)).unwrap_or(&0)
            } else {
                0
            }
        })
        .sum::<u64>();

    println!("{}", ans);
}
0