結果

問題 No.800 四平方定理
ユーザー nebocconebocco
提出日時 2020-08-18 21:49:49
言語 Rust
(1.77.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 1,767 bytes
コンパイル時間 454 ms
コンパイル使用メモリ 172,380 KB
実行使用メモリ 53,160 KB
最終ジャッジ日時 2024-04-20 07:57:17
合計ジャッジ時間 2,808 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,948 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 41 ms
26,832 KB
testcase_11 AC 44 ms
29,512 KB
testcase_12 AC 52 ms
30,988 KB
testcase_13 AC 38 ms
27,148 KB
testcase_14 AC 42 ms
28,648 KB
testcase_15 AC 47 ms
29,928 KB
testcase_16 AC 45 ms
29,340 KB
testcase_17 AC 44 ms
28,284 KB
testcase_18 AC 54 ms
31,940 KB
testcase_19 AC 53 ms
32,364 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 53 ms
33,584 KB
testcase_23 AC 100 ms
53,160 KB
testcase_24 AC 88 ms
48,544 KB
testcase_25 AC 96 ms
52,188 KB
testcase_26 AC 1 ms
6,944 KB
testcase_27 AC 1 ms
6,944 KB
testcase_28 AC 93 ms
48,372 KB
testcase_29 AC 99 ms
50,420 KB
testcase_30 AC 91 ms
48,452 KB
testcase_31 AC 89 ms
45,056 KB
testcase_32 AC 100 ms
48,936 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable does not need to be mutable
  --> main.rs:10:13
   |
10 |           let mut s = {
   |               ----^
   |               |
   |               help: remove this `mut`
...
62 | /     input!{
63 | |         n:usize, d:usize
64 | |     }
   | |_____- in this macro invocation
   |
   = note: `#[warn(unused_mut)]` on by default
   = note: this warning originates in the macro `input` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: 1 warning emitted

ソースコード

diff #

#![allow(dead_code)]
#![allow(non_snake_case)]

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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_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_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, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn gcd(a:i32, b:i32) -> i32 {
    if b == 0 {
        a
    } else {
        gcd(b, a%b)
    }
}

fn main() {
    input!{
        n:usize, d:usize
    }
    let m = n * n * 2 + 1;
    let mut f = vec![0; m];
    let mut g = vec![0; m];
    for x in 1..n+1 {
        for y in 1..n+1 {
            f[x * x + y * y] += 1;
            if x * x < y * y + d && y * y + d < m + x * x{
                g[y * y + d - x * x] += 1;
            }
        }
    }
    let ans = f.iter().zip(g).fold(0, |acc, (x, y)| acc + x * y);
    println!("{}", ans);
}
0