結果

問題 No.1665 quotient replace
ユーザー StrorkisStrorkis
提出日時 2021-09-03 23:25:08
言語 Rust
(1.77.0)
結果
AC  
実行時間 163 ms / 3,000 ms
コード長 3,387 bytes
コンパイル時間 1,059 ms
コンパイル使用メモリ 155,352 KB
実行使用メモリ 17,588 KB
最終ジャッジ日時 2023-08-22 01:23:21
合計ジャッジ時間 5,642 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
9,664 KB
testcase_01 AC 12 ms
9,652 KB
testcase_02 AC 11 ms
9,660 KB
testcase_03 AC 11 ms
9,568 KB
testcase_04 AC 13 ms
9,672 KB
testcase_05 AC 11 ms
9,656 KB
testcase_06 AC 12 ms
9,612 KB
testcase_07 AC 12 ms
9,580 KB
testcase_08 AC 12 ms
9,664 KB
testcase_09 AC 16 ms
9,904 KB
testcase_10 AC 61 ms
12,316 KB
testcase_11 AC 122 ms
15,548 KB
testcase_12 AC 24 ms
10,408 KB
testcase_13 AC 158 ms
17,588 KB
testcase_14 AC 160 ms
17,456 KB
testcase_15 AC 159 ms
17,396 KB
testcase_16 AC 158 ms
17,452 KB
testcase_17 AC 163 ms
17,464 KB
testcase_18 AC 12 ms
9,644 KB
testcase_19 AC 13 ms
9,652 KB
testcase_20 AC 13 ms
9,656 KB
testcase_21 AC 14 ms
9,664 KB
testcase_22 AC 13 ms
9,648 KB
testcase_23 AC 12 ms
9,676 KB
testcase_24 AC 13 ms
9,664 KB
testcase_25 AC 13 ms
9,664 KB
testcase_26 AC 14 ms
9,612 KB
testcase_27 AC 13 ms
9,672 KB
testcase_28 AC 16 ms
9,920 KB
testcase_29 AC 18 ms
10,144 KB
testcase_30 AC 50 ms
13,808 KB
testcase_31 AC 69 ms
15,864 KB
testcase_32 AC 119 ms
15,408 KB
testcase_33 AC 53 ms
11,776 KB
testcase_34 AC 98 ms
14,352 KB
testcase_35 AC 90 ms
13,816 KB
testcase_36 AC 92 ms
14,084 KB
testcase_37 AC 85 ms
13,820 KB
testcase_38 AC 100 ms
14,572 KB
testcase_39 AC 76 ms
13,032 KB
testcase_40 AC 75 ms
13,000 KB
testcase_41 AC 72 ms
12,976 KB
testcase_42 AC 12 ms
9,660 KB
testcase_43 AC 13 ms
9,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

pub mod io {
    use std::io::{BufRead, ErrorKind};

    pub fn scan<R: BufRead>(r: &mut R) -> Vec<u8> {
        let mut res = Vec::new();
        loop {
            let buf = match r.fill_buf() {
                Ok(buf) => buf,
                Err(e) if e.kind() == ErrorKind::Interrupted => continue,
                Err(e) => panic!("{}", e), 
            };
            let (done, used, buf) = {
                match buf.iter().position(u8::is_ascii_whitespace) {
                    Some(i) => (i > 0 || res.len() > 0, i + 1, &buf[..i]),
                    None => (buf.is_empty(), buf.len(), buf),
                }
            };
            res.extend_from_slice(buf);
            r.consume(used);
            if done { return res; }
        }
    }

    #[macro_export]
    macro_rules! scan {
        ($r:expr, [$t:tt; $n:expr]) => {
            (0..$n).map(|_| scan!($r, $t)).collect::<Vec<_>>()
        };
        ($r:expr, [$t:tt]) => {
            scan!($r, [$t; scan!($r, usize)])
        };
        ($r:expr, ($($t:tt),*)) => {
            ($(scan!($r, $t)),*)
        };
        ($r:expr, Usize1) => {
            scan!($r, usize) - 1
        };
        ($r:expr, Bytes) => {
            io::scan($r)
        };
        ($r:expr, String) => {
            String::from_utf8(scan!($r, Bytes)).unwrap()
        };
        ($r:expr, $t:ty) => {
            scan!($r, String).parse::<$t>().unwrap()
        };
    }

    #[macro_export]
    macro_rules! input {
        ($r:expr, $($($v:ident)* : $t:tt),* $(,)?) => {
            $(let $($v)* = scan!($r, $t);)*
        };
    }
}

pub mod prime_factorize {
    pub struct PrimeFactorize {
        mpf: Vec<usize>,
    }
    
    impl PrimeFactorize {
        pub fn new(n: usize) -> Self {
            let mut mpf = (0..=n).collect::<Vec<_>>();
            for i in 2.. {
                if i * i > n {
                    break;
                }
                if mpf[i] < i {
                    continue;
                }
                for j in (i * i..=n).step_by(i) {
                    if mpf[j] == j {
                        mpf[j] = i;
                    }
                }
            }
            Self {
                mpf,
            }
        }
    
        pub fn prime_factorize(&self, mut n: usize) -> Vec<usize> {
            let mut res = Vec::new();
            while n > 1 {
                res.push(self.mpf[n]);
                n /= self.mpf[n];
            }
            res
        }
    
        pub fn count_prime_factors(&self, mut n: usize) -> usize {
            let mut res = 0;
            while n > 1 {
                res += 1;
                n /= self.mpf[n];
            }
            res
        }
    }    
}

use prime_factorize::PrimeFactorize;

const MAX: usize = 1_000_000;

fn run<R: std::io::BufRead, W: std::io::Write>(reader: &mut R, writer: &mut W) {
    input! {
        reader,
        n: usize,
        a: [usize; n],
    }

    let pf = PrimeFactorize::new(MAX);

    let mut xor = 0;
    for a in a {
        xor ^= pf.count_prime_factors(a);
    }

    writeln!(writer, "{}", if xor > 0 { "white" } else { "black" }).ok();
}

fn main() {
    let (stdin, stdout) = (std::io::stdin(), std::io::stdout());
    let ref mut reader = std::io::BufReader::new(stdin.lock());
    let ref mut writer = std::io::BufWriter::new(stdout.lock());
    run(reader, writer);
}
0