結果

問題 No.672 最長AB列
ユーザー taotao54321taotao54321
提出日時 2018-09-28 23:43:44
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,967 bytes
コンパイル時間 3,456 ms
コンパイル使用メモリ 167,168 KB
実行使用メモリ 9,556 KB
最終ジャッジ日時 2024-04-20 12:10:19
合計ジャッジ時間 3,566 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 0 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 17 ms
9,556 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 7 ms
5,376 KB
testcase_14 WA -
testcase_15 AC 7 ms
5,376 KB
testcase_16 AC 6 ms
5,376 KB
testcase_17 AC 12 ms
6,288 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(non_snake_case)]

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut tokens = $s.split_whitespace();
        input_inner! { tokens, $($r)* }
    };

    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut res = String::new();
            ::std::io::stdin().read_to_string(&mut res).unwrap();
            res
        };
        let mut tokens = s.split_whitespace();
        input_inner! { tokens, $($r)* }
    };
}

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

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

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

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

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

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

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

use std::collections::{ HashMap };

fn chmax<T>(xmax: &mut T, x: T) -> bool
    where T: PartialOrd + Copy
{
    if *xmax < x {
        *xmax = x;
        true
    }
    else {
        false
    }
}

fn main() {
    input! {
        S: chars,
    }

    let mut lefts = HashMap::<i32,usize>::new();
    lefts.insert(0, 0);

    let mut ans = 0;
    let mut h = 0;
    for (i,c) in S.into_iter().enumerate() {
        match c {
            'A' => { h += 1; },
            'B' => { h -= 1; },
            _   => { panic!(); },
        }
        let l = *lefts.entry(h).or_insert(i);
        chmax(&mut ans, i-l);
    }

    println!("{}", ans);
}
0