Submission #3423871


Source Code Expand

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

const MAP: [char; 5] = ['A', 'B', 'C', '-', '-'];
const MOD: usize = 1000000007;

fn solve(s: &[char], i: usize, c: usize) -> usize {
    if i == s.len() {
        return if c == 3 { 1 } else { 0 };
    };
    let mut a1 = 0;
    if c != 3 && (s[i] == MAP[c] || s[i] == '?') {
        a1 = solve(s, i+1, c+1);
    }
    let mut a2 = solve(s, i+1, c);
    if s[i] == '?' {
        a2 = 3 * a2 % MOD;
    }
    (a1 + a2) % MOD
}

fn main() {
    input!{
      ss: chars,
    }
    let ans = solve(&ss, 0, 0);
    println!("{}", ans);
}

Submission Info

Submission Time
Task D - We Love ABC
User arzk
Language Rust (1.15.1)
Score 0
Code Size 2275 Byte
Status TLE
Exec Time 2104 ms
Memory 11004 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 11
TLE × 12
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23
Case Name Status Exec Time Memory
a01 AC 2 ms 4352 KB
a02 AC 2 ms 4352 KB
a03 AC 2 ms 4352 KB
b04 AC 2 ms 4352 KB
b05 AC 2 ms 4352 KB
b06 AC 2 ms 4352 KB
b07 AC 2 ms 4352 KB
b08 AC 2 ms 4352 KB
b09 AC 2 ms 4352 KB
b10 AC 6 ms 8956 KB
b11 TLE 2103 ms 11004 KB
b12 TLE 2104 ms 8956 KB
b13 TLE 2104 ms 8956 KB
b14 TLE 2104 ms 8956 KB
b15 TLE 2104 ms 8956 KB
b16 TLE 2104 ms 8956 KB
b17 TLE 2104 ms 8956 KB
b18 TLE 2103 ms 4988 KB
b19 AC 256 ms 4352 KB
b20 TLE 2103 ms 5244 KB
b21 TLE 2104 ms 8956 KB
b22 TLE 2104 ms 8956 KB
b23 TLE 2104 ms 8956 KB