結果
| 問題 |
No.688 E869120 and Constructing Array 2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-01-25 01:52:16 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 1,000 ms |
| コード長 | 1,493 bytes |
| コンパイル時間 | 12,444 ms |
| コンパイル使用メモリ | 391,692 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-15 06:39:35 |
| 合計ジャッジ時間 | 13,491 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 |
ソースコード
#[macro_export]
macro_rules! setup {
{ mut $input:ident: SplitWhitespace $(,)? } => {
use std::io::Read;
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).ok();
let mut $input = buf.split_whitespace();
};
}
#[macro_export]
macro_rules! parse_next {
($str_iter:expr) => {
$str_iter.next().unwrap().parse().ok().unwrap()
};
}
fn main() {
setup! { mut input: SplitWhitespace };
let k: usize = parse_next!(input);
let mut comb_n_2 = vec![];
{
comb_n_2.push(0);
comb_n_2.push(0);
}
for i in 2..=30 {
comb_n_2.push(comb_n_2[i - 1] + (i - 1));
}
let ans = match (|| {
if k == 0 {
return (1, 1);
}
for i in 2..=30 {
let log2 = f64::log2((k as f64) / (comb_n_2[i] as f64));
if log2.trunc() == log2 {
if i + (log2 as usize) <= 30 {
return (i, log2 as usize);
}
}
}
unreachable!();
})() {
(i, j) => {
let mut output = String::new();
output.push_str(&format!("{}", i + j));
output.push('\n');
(0..i).for_each(|_| output.push_str(&format!("{} ", 1)));
(0..j).for_each(|_| output.push_str(&format!("{} ", 0)));
output = output.trim_end().to_owned();
output.push('\n');
output
}
};
println!("{}", ans);
}