結果
問題 | No.1694 ZerOne |
ユーザー | akakimidori |
提出日時 | 2021-11-16 00:14:46 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 103 ms / 2,000 ms |
コード長 | 4,477 bytes |
コンパイル時間 | 14,482 ms |
コンパイル使用メモリ | 378,728 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-05-09 01:06:20 |
合計ジャッジ時間 | 17,718 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,812 KB |
testcase_02 | AC | 1 ms
6,812 KB |
testcase_03 | AC | 52 ms
6,816 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 6 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,944 KB |
testcase_07 | AC | 4 ms
6,944 KB |
testcase_08 | AC | 9 ms
6,940 KB |
testcase_09 | AC | 48 ms
6,940 KB |
testcase_10 | AC | 4 ms
6,940 KB |
testcase_11 | AC | 1 ms
6,940 KB |
testcase_12 | AC | 0 ms
6,944 KB |
testcase_13 | AC | 13 ms
6,940 KB |
testcase_14 | AC | 47 ms
6,940 KB |
testcase_15 | AC | 8 ms
6,944 KB |
testcase_16 | AC | 6 ms
6,940 KB |
testcase_17 | AC | 1 ms
6,940 KB |
testcase_18 | AC | 1 ms
6,940 KB |
testcase_19 | AC | 1 ms
6,940 KB |
testcase_20 | AC | 101 ms
6,944 KB |
testcase_21 | AC | 101 ms
6,940 KB |
testcase_22 | AC | 95 ms
6,940 KB |
testcase_23 | AC | 103 ms
6,940 KB |
testcase_24 | AC | 101 ms
6,940 KB |
testcase_25 | AC | 102 ms
6,944 KB |
testcase_26 | AC | 88 ms
6,940 KB |
testcase_27 | AC | 82 ms
6,940 KB |
testcase_28 | AC | 37 ms
6,940 KB |
testcase_29 | AC | 44 ms
6,940 KB |
testcase_30 | AC | 56 ms
6,944 KB |
testcase_31 | AC | 81 ms
6,940 KB |
testcase_32 | AC | 70 ms
6,944 KB |
testcase_33 | AC | 82 ms
6,940 KB |
コンパイルメッセージ
warning: unused import: `std::io::Write` --> src/main.rs:68:5 | 68 | use std::io::Write; | ^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: function `rand_memory` is never used --> src/main.rs:1:4 | 1 | fn rand_memory() -> usize { | ^^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default warning: function `rand` is never used --> src/main.rs:5:4 | 5 | fn rand() -> usize { | ^^^^ warning: type alias `Set` is never used --> src/main.rs:71:6 | 71 | type Set<T> = BTreeSet<T>; | ^^^ warning: function `test` is never used --> src/main.rs:100:4 | 100 | fn test() { | ^^^^
ソースコード
fn rand_memory() -> usize { Box::into_raw(Box::new("I hope this is a random number")) as usize } fn rand() -> usize { static mut X: usize = 0; unsafe { if X == 0 { X = rand_memory(); } X ^= X << 13; X ^= X >> 17; X ^= X << 5; X } } // ---------- begin input macro ---------- // reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::<Vec<char>>() }; ($iter:expr, bytes) => { read_value!($iter, String).bytes().collect::<Vec<u8>>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } // ---------- end input macro ---------- use std::collections::*; use std::io::Write; type Map<K, V> = BTreeMap<K, V>; type Set<T> = BTreeSet<T>; fn run() { input! { s: bytes, } let mut cnt = [0; 2]; let mut sum = 0; for (i, s) in s.iter().enumerate() { let x = (*s - b'0') as usize; cnt[x] += 1; if x == 0 { sum += i; } } let mut dp = Map::new(); dp.insert((0, 0), 1u64); for i in 0..s.len() { let mut next = Map::new(); for ((z, s), w) in dp { *next.entry((z + 1, s + i)).or_insert(0) += w; *next.entry((z, s)).or_insert(0) += w; } dp = next; } let ans = *dp.get(&(cnt[0], sum)).unwrap(); println!("{}", ans); } fn test() { for _ in 0..100000 { let n = 12; let ini = (0..n).map(|_| rand() & 1).collect::<Vec<_>>(); let mut set = Set::new(); set.insert(ini.clone()); let mut dfs = vec![ini.clone()]; while let Some(s) = dfs.pop() { for len in 1..=n { for i in 0..=(n - len) { for j in (i + len)..=(n - len) { let mut a = Vec::from(&s[i..(i + len)]); let mut b = Vec::from(&s[j..(j + len)]); a.sort(); b.sort(); if a == b { let mut s = s.clone(); for k in 0..len { s.swap(i + k, j + k); } if set.insert(s.clone()) { dfs.push(s); } } } } } } let save = set; let mut set = Set::new(); set.insert(ini.clone()); let mut dfs = vec![ini]; while let Some(s) = dfs.pop() { for len in 2..=2 { for i in 0..=(n - len) { for j in (i + len)..=(n - len) { let mut a = Vec::from(&s[i..(i + len)]); let mut b = Vec::from(&s[j..(j + len)]); a.sort(); b.sort(); if a == b { let mut s = s.clone(); for k in 0..len { s.swap(i + k, j + k); } if set.insert(s.clone()) { dfs.push(s); } } } } } } assert_eq!(set, save); } } fn main() { run(); }