結果

問題 No.672 最長AB列
ユーザー lzy9lzy9
提出日時 2018-04-13 22:51:09
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 1,017 bytes
コンパイル時間 3,037 ms
コンパイル使用メモリ 158,556 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 00:06:56
合計ジャッジ時間 8,011 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `min`
 --> Main.rs:3:16
  |
3 | use std::cmp::{min, max};
  |                ^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused import: `std::mem::swap`
 --> Main.rs:4:5
  |
4 | use std::mem::swap;
  |     ^^^^^^^^^^^^^^

warning: unused import: `std::collections::HashMap`
 --> Main.rs:5:5
  |
5 | use std::collections::HashMap;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^

warning: static `DX` is never used
  --> Main.rs:19:8
   |
19 | static DX: &'static [i32] = &[0, 0, 1, -1];
   |        ^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: static `DY` is never used
  --> Main.rs:20:8
   |
20 | static DY: &'static [i32] = &[1, -1, 0, 0];
   |        ^^

warning: 5 warnings emitted

ソースコード

diff #

use std::io::*;
use std::str::FromStr;
use std::cmp::{min, max};
use std::mem::swap;
use std::collections::HashMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin_lock = stdin.lock();
    let s = stdin_lock
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

static DX: &'static [i32] = &[0, 0, 1, -1];
static DY: &'static [i32] = &[1, -1, 0, 0];

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

    let mut cnt = vec![0 as i32; s.len() + 1];

    let mut t = 0;

    for (i, c) in s.chars().enumerate() {
        if c == 'A' {
            t += 1;
        } else {
            t -= 1;
        }

        cnt[i + 1] = t;
    }

    let mut ans = 0;

    for i in 0..cnt.len() - 1 {
        for j in i + 1..cnt.len() {
            if cnt[i] == cnt[j] {
                ans = max(ans, j - i);
            }
        }
    }

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