結果

問題 No.672 最長AB列
ユーザー どららどらら
提出日時 2018-04-13 23:43:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 630 bytes
コンパイル時間 1,871 ms
コンパイル使用メモリ 173,632 KB
実行使用メモリ 12,748 KB
最終ジャッジ日時 2023-09-10 04:12:01
合計ジャッジ時間 3,200 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 86 ms
12,748 KB
testcase_10 AC 61 ms
8,072 KB
testcase_11 AC 56 ms
8,080 KB
testcase_12 AC 14 ms
4,376 KB
testcase_13 AC 14 ms
4,384 KB
testcase_14 AC 13 ms
4,384 KB
testcase_15 AC 14 ms
4,384 KB
testcase_16 AC 14 ms
4,380 KB
testcase_17 AC 61 ms
8,140 KB
testcase_18 AC 7 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  string s;
  cin >> s;

  int ret = 0;
  map<int,int> memo;
  memo[0] = 0;
  int level = 0;
  rep(i,s.size()){
    if(s[i] == 'A') level++;
    else level--;

    if(memo.count(level)>0){
      ret = max(ret, i+1-memo[level]);
    }else{
      memo[level] = i+1;
    }
  }

  cout << ret << endl;
  
  return 0;
}

0