結果
| 問題 |
No.103 素因数ゲーム リターンズ
|
| コンテスト | |
| ユーザー |
fukafukatani
|
| 提出日時 | 2019-02-04 23:11:28 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,660 bytes |
| コンパイル時間 | 16,639 ms |
| コンパイル使用メモリ | 378,188 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-26 03:23:26 |
| 合計ジャッジ時間 | 17,871 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 20 |
コンパイルメッセージ
warning: unused variable: `n` --> src/main.rs:56:9 | 56 | let n = read::<usize>(); | ^ help: if this is intentional, prefix it with an underscore: `_n` | = note: `#[warn(unused_variables)]` on by default
ソースコード
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
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()
}
fn get_primes() -> Vec<usize> {
let n = 10000;
let mut is_prime = vec![true; n];
let mut primes = Vec::new();
is_prime[0] = false;
is_prime[1] = false;
for i in 2..n {
if is_prime[i] {
primes.push(i);
let mut j = 2 * i;
while j < n {
is_prime[j] = false;
j += i;
}
}
}
primes
}
fn factorize(num: usize, primes: &Vec<usize>) -> Vec<usize> {
let mut factors: Vec<usize> = Vec::new();
let mut num = num;
for p in primes {
let mut new_factor = 0;
while num % p == 0 {
new_factor += 1;
num /= p;
}
if new_factor >= 1 {
factors.push(new_factor);
}
}
factors
}
fn main() {
let n = read::<usize>();
let a: Vec<usize> = read_vec();
let primes = get_primes();
let mut mountains = Vec::new();
for num in a {
let mut factors = factorize(num, &primes);
mountains.append(&mut factors);
}
let grundy_all = mountains
.iter()
.map(|&x| x % 3)
.fold(0usize, |acc, x| acc ^ x);
if grundy_all == 0 {
println!("Bob");
} else {
println!("Alice");
}
}
fukafukatani