結果

問題 No.346 チワワ数え上げ問題
ユーザー sinosino
提出日時 2020-04-13 13:05:49
言語 Rust
(1.77.0)
結果
RE  
実行時間 -
コード長 1,520 bytes
コンパイル時間 2,569 ms
コンパイル使用メモリ 158,860 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-24 23:22:19
合計ジャッジ時間 6,886 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 0 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 RE -
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::collections::HashMap;
use std::collections::HashSet;

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_end().to_owned()
}

fn main() {
    let s = read!(String);

    let cw: Vec<char> = s.chars().filter(|c| c == &'c' || c == &'w').collect();

    let mut table_w = Vec::<usize>::with_capacity(cw.len());
    for _ in 0..cw.len() {
        table_w.push(0);
    }

    for i in (0..cw.len()-1).rev() {
        let dif = if cw[i+1] == 'w' {1} else {0};
        table_w[i] = table_w[i+1] + dif;
    }

    let mut acc = 0;
    for (i, c) in cw.iter().enumerate() {
        if c == &'c' {
            acc += combination(table_w[i], 2);
        }
    }
    println!("{}", acc);
}

fn combination(n: usize, r: usize) -> usize {
    if n < r {0}
    else if n * r == 0 || n == r {1}
    else { combination(n-1, r-1) + combination(n-1, r) }
}
0