QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#236737#7686. The Phantom Menaceucup-team635#RE 0ms0kbRust2.8kb2023-11-04 10:27:172023-11-04 10:27:18

Judging History

你现在查看的是最新测评结果

  • [2024-10-08 14:11:03]
  • hack成功,自动添加数据
  • (/hack/941)
  • [2024-10-08 10:05:28]
  • hack成功,自动添加数据
  • (/hack/940)
  • [2024-10-07 19:51:15]
  • hack成功,自动添加数据
  • (/hack/938)
  • [2024-10-07 19:28:01]
  • hack成功,自动添加数据
  • (/hack/937)
  • [2024-10-07 17:16:32]
  • hack成功,自动添加数据
  • (/hack/936)
  • [2024-10-07 16:53:09]
  • hack成功,自动添加数据
  • (/hack/935)
  • [2024-10-07 16:22:17]
  • hack成功,自动添加数据
  • (/hack/934)
  • [2023-11-04 10:27:18]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-11-04 10:27:17]
  • 提交

answer

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() {
    input! {
        w: usize,
        h: usize,
        a: [[usize1; w]; h],
    }
    let f = |a: &[u8], b: &[u8]| -> Vec<u8> {
        let mut c = vec![0; w];
        for (c, b) in c.iter_mut().zip(b.iter()) {
            *c = a[*b as usize];
        }
        c
    };
    let a = a.into_iter().map(|a| a.into_iter().map(|a| a as u8).collect()).collect::<Vec<Vec<_>>>();
    let mut ans = 0;
    if h <= 18 {
        let mut dp = vec![];
        for bit in 1..(1 << h) {
            let mut p = (0..w).map(|i| i as u8).collect::<Vec<_>>();
            for (i, a) in a.iter().enumerate().rev() {
                if bit >> i & 1 == 1 {
                    p = f(a, &p);
                }
            }
            dp.push(p);
        }
        dp.sort();
        dp.dedup();
        ans = dp.len();
    } else {
        let mut dp = vec![];
        for a in a.iter().rev() {
            let mut next = dp.clone();
            next.push(a.clone());
            for b in dp.iter() {
                next.push(f(a, b));
            }
            dp = next;
            dp.sort();
            dp.dedup();
        }
        ans = dp.len();
    }
    println!("{}", ans);
}

// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[macro_export]
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_export]
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_export]
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 ----------

详细

Test #1:

score: 0
Runtime Error

input:

2
3 3
abc
ghi
def
bcd
efg
hia
1 3
abc
def

output:


result: