結果

問題 No.1200 お菓子配り-3
ユーザー fukafukatanifukafukatani
提出日時 2020-08-28 22:20:25
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,346 bytes
コンパイル時間 1,161 ms
コンパイル使用メモリ 178,620 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-26 23:32:24
合計ジャッジ時間 16,498 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 0 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 13 ms
6,940 KB
testcase_08 AC 12 ms
6,940 KB
testcase_09 AC 12 ms
6,940 KB
testcase_10 AC 11 ms
6,940 KB
testcase_11 AC 11 ms
6,940 KB
testcase_12 AC 107 ms
6,944 KB
testcase_13 AC 106 ms
6,940 KB
testcase_14 AC 108 ms
6,940 KB
testcase_15 AC 109 ms
6,940 KB
testcase_16 AC 108 ms
6,940 KB
testcase_17 AC 390 ms
6,944 KB
testcase_18 AC 562 ms
6,944 KB
testcase_19 AC 128 ms
6,940 KB
testcase_20 AC 1,097 ms
6,944 KB
testcase_21 AC 1,086 ms
6,944 KB
testcase_22 AC 1,277 ms
6,940 KB
testcase_23 AC 1,077 ms
6,944 KB
testcase_24 AC 1,084 ms
6,944 KB
testcase_25 AC 1,066 ms
6,940 KB
testcase_26 AC 1,074 ms
6,944 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 1,436 ms
6,944 KB
testcase_29 AC 1,644 ms
6,944 KB
testcase_30 AC 1,663 ms
6,940 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `i`
  --> main.rs:94:9
   |
94 |     for i in 0..s {
   |         ^ help: if this is intentional, prefix it with an underscore: `_i`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

diff #

#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn solve() {
    let v = read_vec::<i64>();
    let (x, y) = (max(v[0], v[1]), min(v[0], v[1]));

    if x == y {
        solve_eq(x);
        return;
    }

    let mut x_m_y_factors = vec![];
    for i in 1.. {
        if i * i > x - y {
            break;
        }
        if (x - y) % i == 0 {
            x_m_y_factors.push(i);
            if i != (x - y) / i {
                x_m_y_factors.push((x - y) / i);
            }
        }
    }

    let mut x_p_y_factors = BTreeSet::new();
    for i in 1.. {
        if i * i > x + y {
            break;
        }
        if (x + y) % i == 0 {
            x_p_y_factors.insert(i);
            x_p_y_factors.insert((x + y) / i);
        }
    }

    let mut ans = 0i64;
    for x_m_y_fact in x_m_y_factors {
        if !x_p_y_factors.contains(&(x_m_y_fact + 2)) {
            continue;
        }

        let a = x_m_y_fact + 1;
        let b_m_c = (x - y) / (a - 1);
        let b_p_c = (x + y) / (a + 1);
        if (b_m_c + b_p_c) % 2 == 1 {
            continue;
        }
        let b = (b_m_c + b_p_c) / 2;
        let c = b_p_c - b;
        if b > 0 && c > 0 {
            ans += 1;
        }
    }
    println!("{}", ans);
}

fn solve_eq(x: i64) {
    // a == 1
    let mut ans = x - 1;

    let mut x_factors = vec![];
    for i in 1.. {
        if i * i > x {
            break;
        }
        if x % i == 0 {
            x_factors.push(i);
            if i != x / i {
                x_factors.push(x / i);
            }
        }
    }
    ans += x_factors.len() as i64 - 1;
    println!("{}", ans);
}

fn main() {
    let s = read::<usize>();
    for i in 0..s {
        solve();
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
0