結果
| 問題 |
No.1200 お菓子配り-3
|
| コンテスト | |
| ユーザー |
fukafukatani
|
| 提出日時 | 2020-08-28 22:30:32 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,116 bytes |
| コンパイル時間 | 12,316 ms |
| コンパイル使用メモリ | 398,012 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-14 15:49:38 |
| 合計ジャッジ時間 | 19,626 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 29 WA * 2 |
コンパイルメッセージ
warning: unused variable: `i`
--> src/main.rs:85:9
|
85 | for i in 0..s {
| ^ help: if this is intentional, prefix it with an underscore: `_i`
|
= note: `#[warn(unused_variables)]` on by default
ソースコード
#![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 ans = 0i64;
for &x_m_y_fact in &x_m_y_factors {
if (x + y) % (x_m_y_fact + 2) != 0 {
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;
} else {
}
}
// debug!(ans, x_m_y_factors.len());
println!("{}", ans);
}
fn solve_eq(x: i64) {
// a == 1
let mut ans = x - 1;
let mut x_factors = 0;
for i in 1.. {
if i * i > x {
break;
}
if x % i == 0 {
x_factors += 1;
if i != x / i {
x_factors += 1;
}
}
}
ans += x_factors - 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()
}
fukafukatani