結果

問題 No.1665 quotient replace
ユーザー ziitaziita
提出日時 2021-09-03 22:05:10
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 3,358 bytes
コンパイル時間 1,944 ms
コンパイル使用メモリ 166,156 KB
実行使用メモリ 18,248 KB
最終ジャッジ日時 2023-08-21 21:59:13
合計ジャッジ時間 11,409 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
10,392 KB
testcase_01 AC 18 ms
10,436 KB
testcase_02 AC 17 ms
10,452 KB
testcase_03 WA -
testcase_04 AC 17 ms
10,436 KB
testcase_05 AC 18 ms
10,392 KB
testcase_06 AC 22 ms
10,504 KB
testcase_07 AC 17 ms
10,372 KB
testcase_08 AC 19 ms
10,412 KB
testcase_09 AC 31 ms
10,612 KB
testcase_10 AC 188 ms
13,072 KB
testcase_11 AC 404 ms
16,352 KB
testcase_12 AC 57 ms
11,020 KB
testcase_13 AC 520 ms
18,176 KB
testcase_14 AC 525 ms
18,208 KB
testcase_15 AC 533 ms
18,204 KB
testcase_16 AC 522 ms
18,212 KB
testcase_17 AC 527 ms
18,248 KB
testcase_18 AC 17 ms
10,432 KB
testcase_19 AC 17 ms
10,448 KB
testcase_20 AC 16 ms
10,388 KB
testcase_21 AC 17 ms
10,428 KB
testcase_22 WA -
testcase_23 AC 17 ms
10,436 KB
testcase_24 AC 18 ms
10,400 KB
testcase_25 WA -
testcase_26 AC 18 ms
10,436 KB
testcase_27 AC 21 ms
10,556 KB
testcase_28 AC 28 ms
10,656 KB
testcase_29 AC 37 ms
10,976 KB
testcase_30 AC 176 ms
14,320 KB
testcase_31 AC 257 ms
16,476 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 274 ms
14,360 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 233 ms
13,776 KB
testcase_42 AC 17 ms
10,404 KB
testcase_43 AC 17 ms
10,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports)]
#![allow(non_snake_case, unused)]

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

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

use std::io::Write;
use std::collections::*;
use std::cmp::*;
use std::ops::*;
use std::marker::*;

const INF: i64 = std::i64::MAX/100;
const MOD: i64 = 1_000_000_007;
// const MOD: i64 = 998244353;

struct SieveOfEratosthenes {
    primes: Vec<usize>,
    divs: Vec<usize>,
}

impl SieveOfEratosthenes {
    pub fn new(n: usize) -> Self {
        let mut divs = vec![1;n+1];
        for i in 2..=n {
            if divs[i]!=1 {
                continue;
            }
            for j in 1..=n {
                let val = i*j;
                if val>n {
                    break;
                }
                divs[val as usize] = i;
            }
        }
        let mut primes = divs.iter()
                             .enumerate()
                             .filter(|x| *x.1>1 && x.0==*x.1)
                             .map(|x| *x.1)
                             .collect::<Vec<usize>>();
        SieveOfEratosthenes {
            divs,
            primes,
        }
    }
    pub fn factors(&self, n: usize) -> Vec<(usize,usize)> {
        assert!(n+1<=self.divs.len());
        let mut ans = vec![];
        let mut x = n;
        while x > 1 {
            let nxt = self.divs[x];
            ans.push(nxt);
            x /= nxt;
        }
        let mut map = HashMap::<usize,usize>::new();
        for &a in &ans {
            *map.entry(a).or_insert(0) += 1;
        }
        let mut ret = vec![];
        for (&k,&v) in map.iter() {
            ret.push((k,v));
        }
        ret
    }
}

fn main() {
    input! {
        n: (i64),
        a: [usize;n],
    }
    let mut p = SieveOfEratosthenes::new(1000001);
    let mut x = 0;
    for &a in &a {
        let q = p.factors(a);
        for (_,y) in &q {
            x ^= y;
        }
    }
    if x==0 {
        println!("black");
    }
    else {
        println!("white");
    }
}
0