結果
問題 | No.688 E869120 and Constructing Array 2 |
ユーザー | くれちー |
提出日時 | 2018-05-18 23:04:03 |
言語 | Rust (1.77.0 + proconio) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,122 bytes |
コンパイル時間 | 25,218 ms |
コンパイル使用メモリ | 378,004 KB |
実行使用メモリ | 8,864 KB |
最終ジャッジ日時 | 2024-07-07 13:35:11 |
合計ジャッジ時間 | 18,825 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
8,860 KB |
testcase_01 | AC | 0 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 0 ms
6,944 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,940 KB |
testcase_09 | TLE | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
ソースコード
fn solve<R: BufRead, W: Write>(_reader: R, _writer: &mut W) { let mut _scanner = Scanner::new(_reader); #[allow(unused_macros)] macro_rules! scan { ($t:ty) => { _scanner.next::<$t>() }; ($($t:ty),+) => { ($(scan!($t)),+) }; ($t:ty; $n:expr) => {{ let mut vec = Vec::with_capacity($n); for _ in 0..$n { vec.push(scan!($t)); } vec }}; ($t_0:ty, $t_1:ty; $n:expr) => { scan!($t_0 = 0, $t_1 = 1; $n) }; ($t_0:ty, $t_1:ty, $t_2:ty; $n:expr) => { scan!($t_0 = 0, $t_1 = 1, $t_2 = 2; $n) }; ($($t:ty = $i:tt),+; $n:expr) => {{ let mut vecs = ($(Vec::<$t>::with_capacity($n)),+); for _ in 0..$n {$( vecs.$i.push(scan!($t)); )+} vecs }}; } #[allow(unused_macros)] macro_rules! println { () => { writeln!(_writer).unwrap() }; ($fmt:expr) => { writeln!(_writer, $fmt).unwrap() }; ($fmt:expr, $($arg:tt)*) => { writeln!(_writer, $fmt, $($arg)*).unwrap() }; } let k = scan!(u64); let mut cnt1 = 2; let mut comb = 1; // 2C2 while k % comb != 0 || !(k / comb).is_power_of_two() { cnt1 += 1; comb *= cnt1; comb /= cnt1 - 2; } let cnt0 = (k / comb).trailing_zeros(); let n = cnt0 as u64 + cnt1; assert_eq!(2u64.pow(cnt0) * comb, k); assert!(1 <= n && n <= 30); println!("{}", n); let mut b_str = String::new(); for _ in 0..cnt0 { b_str += "0 "; } for _ in 0..cnt1 { b_str += "1 "; } println!("{}", b_str); } fn main() { let stdin = stdin(); let stdout = stdout(); #[cfg(debug_assertions)] let mut writer = stdout.lock(); #[cfg(not(debug_assertions))] let mut writer = BufWriter::new(stdout.lock()); solve(stdin.lock(), &mut writer); writer.flush().unwrap(); } use io::Scanner; use std::io::{stdin, stdout, BufRead, BufWriter, Write}; pub mod io { pub use self::scanner::*; mod scanner { use std::fmt::Debug; use std::io::BufRead; use std::str; use std::str::FromStr; pub struct Scanner<R: BufRead> { reader: R, buffer: Vec<u8>, position: usize, } impl<R: BufRead> Scanner<R> { pub fn new(reader: R) -> Self { Scanner { reader: reader, buffer: vec![], position: 0 } } pub fn next<T: FromStr>(&mut self) -> T where T::Err: Debug, { if self.buffer.is_empty() { self.read_line(); } loop { match self.buffer.get(self.position) { Some(&b' ') => self.position += 1, Some(&b'\n') => self.read_line(), Some(_) => break, None => panic!("EOF reached"), } } let start = self.position; loop { match self.buffer.get(self.position) { Some(&b' ') | Some(&b'\n') | None => break, Some(_) => self.position += 1, } } str::from_utf8(&self.buffer[start..self.position]).unwrap().parse().unwrap() } fn read_line(&mut self) { self.position = 0; self.buffer.clear(); self.reader.read_until(b'\n', &mut self.buffer).unwrap(); } } } }