結果
問題 | No.589 Counting Even |
ユーザー | aimy |
提出日時 | 2017-11-04 00:07:30 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,333 bytes |
コンパイル時間 | 13,045 ms |
コンパイル使用メモリ | 377,924 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-05-02 20:55:25 |
合計ジャッジ時間 | 12,489 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 0 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 0 ms
5,376 KB |
testcase_23 | AC | 1 ms
5,376 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 0 ms
5,376 KB |
testcase_27 | WA | - |
testcase_28 | AC | 1 ms
5,376 KB |
ソースコード
fn main() { let n: u64 = get::val(); if n%2 == 1 || n == 0 {println!("0"); return} let t = n.count_ones(); let ans = n - (t as u64) * 2 + 1; println!("{}", ans) } #[allow(dead_code)] mod prime { pub fn is_prime(n: usize) -> bool { let sq = (n as f64).sqrt().floor() as usize; let p = (2..sq+1).all(|d| n%d != 0); p } pub fn primes(n: usize) -> Vec<usize> { if n < 2 {return vec![]} let mut ps = vec![true; n+1]; ps[0] = false; ps[1] = false; for i in 2 .. n+1 { if ps[i] { for k in 2 .. n/i+1 { ps[i*k] = false; } } } ps.iter().enumerate().filter(|&(_,&p)|p).map(|(i,_)|i).collect() } pub fn factorize(n: u64) -> Vec<u64> { let sq = (n as f64).sqrt().floor() as u64; let mut fs = vec![]; let mut x = n; for d in 2 .. sq+1 { if x == 1 {break} while x > 1 && x % d == 0 { fs.push(d); x /= d; } } if x != 1 {fs.push(x)}; fs } } #[allow(dead_code)] mod modulo { pub const MOD: u64 = 1_000_000_007; pub fn plus(x: u64, y: u64) -> u64 { (x + y) % MOD } pub fn mul(x: u64, y: u64) -> u64 { (x * y) % MOD } pub fn pow(x: u64, n: u64) -> u64 { match n { 0 => 1, _ if n % 2 == 1 => mul(x, pow(x, n-1)), _ => { let q = pow(x, n>>1); mul(q, q) } } } } #[allow(dead_code)] mod get { use std::io::*; use std::str::*; pub fn val<T: FromStr>() -> T { let mut buf = String::new(); stdin().read_line(&mut buf).ok(); buf.trim().parse::<T>().ok().unwrap() } pub fn vals<T: FromStr>(n: usize) -> Vec<T> { let mut vec: Vec<T> = vec![]; for _ in 0 .. n { vec.push(val()); } vec } pub fn tuple<T1: FromStr, T2: FromStr>() -> (T1, T2) { let mut buf = String::new(); stdin().read_line(&mut buf).ok(); let mut it = buf.trim().split_whitespace(); let x = it.next().unwrap().parse::<T1>().ok().unwrap(); let y = it.next().unwrap().parse::<T2>().ok().unwrap(); (x, y) } pub fn tuples<T1: FromStr, T2: FromStr>(n: usize) -> Vec<(T1, T2)> { let mut vec: Vec<(T1, T2)> = vec![]; for _ in 0 .. n { vec.push(tuple()); } vec } pub fn tuple3<T1: FromStr, T2: FromStr, T3: FromStr>() -> (T1, T2, T3) { let mut buf = String::new(); stdin().read_line(&mut buf).ok(); let mut it = buf.trim().split_whitespace(); let x = it.next().unwrap().parse::<T1>().ok().unwrap(); let y = it.next().unwrap().parse::<T2>().ok().unwrap(); let z = it.next().unwrap().parse::<T3>().ok().unwrap(); (x, y, z) } pub fn tuple3s<T1: FromStr, T2: FromStr, T3: FromStr>(n: usize) -> Vec<(T1, T2, T3)> { let mut vec: Vec<(T1, T2, T3)> = vec![]; for _ in 0 .. n { vec.push(tuple3()); } vec } pub fn list<T: FromStr>() -> Vec<T> { let mut buf = String::new(); stdin().read_line(&mut buf).ok(); buf.trim().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect() } pub fn lists<T: FromStr>(h: usize) -> Vec<Vec<T>> { let mut mat: Vec<Vec<T>> = vec![]; for _ in 0 .. h { mat.push(list()); } mat } pub fn chars() -> Vec<char> { let mut buf = String::new(); stdin().read_line(&mut buf).ok(); buf.trim().chars().collect() } }