結果

問題 No.2152 [Cherry Anniversary 2] 19 Petals of Cherry
ユーザー akakimidoriakakimidori
提出日時 2022-12-09 00:06:57
言語 Rust
(1.77.0 + proconio)
結果
AC  
実行時間 83 ms / 1,000 ms
コード長 2,028 bytes
コンパイル時間 13,272 ms
コンパイル使用メモリ 376,732 KB
実行使用メモリ 10,140 KB
最終ジャッジ日時 2024-10-14 18:13:44
合計ジャッジ時間 17,650 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
10,112 KB
testcase_01 AC 48 ms
10,112 KB
testcase_02 AC 26 ms
6,816 KB
testcase_03 AC 65 ms
10,080 KB
testcase_04 AC 51 ms
10,028 KB
testcase_05 AC 64 ms
10,040 KB
testcase_06 AC 55 ms
10,112 KB
testcase_07 AC 62 ms
10,108 KB
testcase_08 AC 59 ms
10,040 KB
testcase_09 AC 51 ms
10,040 KB
testcase_10 AC 52 ms
10,140 KB
testcase_11 AC 52 ms
9,948 KB
testcase_12 AC 59 ms
10,076 KB
testcase_13 AC 51 ms
10,028 KB
testcase_14 AC 66 ms
10,012 KB
testcase_15 AC 61 ms
10,048 KB
testcase_16 AC 50 ms
10,088 KB
testcase_17 AC 55 ms
10,036 KB
testcase_18 AC 66 ms
9,968 KB
testcase_19 AC 63 ms
10,036 KB
testcase_20 AC 46 ms
9,992 KB
testcase_21 AC 48 ms
10,036 KB
testcase_22 AC 58 ms
10,084 KB
testcase_23 AC 53 ms
9,976 KB
testcase_24 AC 64 ms
10,012 KB
testcase_25 AC 59 ms
9,892 KB
testcase_26 AC 67 ms
10,064 KB
testcase_27 AC 44 ms
10,028 KB
testcase_28 AC 40 ms
10,112 KB
testcase_29 AC 40 ms
10,112 KB
testcase_30 AC 43 ms
10,112 KB
testcase_31 AC 44 ms
10,112 KB
testcase_32 AC 47 ms
10,112 KB
testcase_33 AC 50 ms
10,112 KB
testcase_34 AC 51 ms
10,004 KB
testcase_35 AC 53 ms
9,984 KB
testcase_36 AC 54 ms
10,112 KB
testcase_37 AC 56 ms
10,112 KB
testcase_38 AC 58 ms
10,112 KB
testcase_39 AC 60 ms
10,112 KB
testcase_40 AC 60 ms
10,092 KB
testcase_41 AC 67 ms
10,088 KB
testcase_42 AC 67 ms
10,096 KB
testcase_43 AC 74 ms
10,084 KB
testcase_44 AC 79 ms
10,052 KB
testcase_45 AC 83 ms
10,048 KB
testcase_46 AC 82 ms
10,040 KB
testcase_47 AC 26 ms
6,820 KB
testcase_48 AC 61 ms
9,896 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `out`
  --> src/main.rs:47:45
   |
47 | fn run<W: Write>(sc: &mut scanner::Scanner, out: &mut std::io::BufWriter<W>) {
   |                                             ^^^ help: if this is intentional, prefix it with an underscore: `_out`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: type alias `Map` is never used
  --> src/main.rs:33:6
   |
33 | type Map<K, V> = BTreeMap<K, V>;
   |      ^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: type alias `Set` is never used
  --> src/main.rs:34:6
   |
34 | type Set<T> = BTreeSet<T>;
   |      ^^^

warning: type alias `Deque` is never used
  --> src/main.rs:35:6
   |
35 | type Deque<T> = VecDeque<T>;
   |      ^^^^^

ソースコード

diff #

// ---------- begin scannner ----------
#[allow(dead_code)]
mod scanner {
    use std::str::FromStr;
    pub struct Scanner<'a> {
        it: std::str::SplitWhitespace<'a>,
    }
    impl<'a> Scanner<'a> {
        pub fn new(s: &'a String) -> Scanner<'a> {
            Scanner {
                it: s.split_whitespace(),
            }
        }
        pub fn next<T: FromStr>(&mut self) -> T {
            self.it.next().unwrap().parse::<T>().ok().unwrap()
        }
        pub fn next_bytes(&mut self) -> Vec<u8> {
            self.it.next().unwrap().bytes().collect()
        }
        pub fn next_chars(&mut self) -> Vec<char> {
            self.it.next().unwrap().chars().collect()
        }
        pub fn next_vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
            (0..len).map(|_| self.next()).collect()
        }
    }
}
// ---------- end scannner ----------

use std::io::Write;
use std::collections::*;

type Map<K, V> = BTreeMap<K, V>;
type Set<T> = BTreeSet<T>;
type Deque<T> = VecDeque<T>;

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut sc = scanner::Scanner::new(&s);
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    run(&mut sc, &mut out);
}

fn run<W: Write>(sc: &mut scanner::Scanner, out: &mut std::io::BufWriter<W>) {
    let m = 19;
    let mut dp = vec![[0u64; 2]; 1 << m];
    dp[0][0] = 1;
    for i in 0..m {
        let l: usize = sc.next();
        let a = (0..l).map(|_| sc.next::<usize>() - 1).collect::<Vec<_>>();
        for j in (0usize..(1 << m)).filter(|bit| bit.count_ones() == (i as u32)) {
            let v = dp[j];
            for &a in a.iter().filter(|&&a| j >> a & 1 == 0) {
                let c = (j >> a).count_ones() as usize & 1;
                let x = j | (1 << a);
                dp[x][c] += v[0];
                dp[x][c ^ 1] += v[1];
            }
        }
    }
    let ans = dp[(1 << m) - 1];
    println!("{} {}", ans[0], ans[1]);
}
0