結果

問題 No.672 最長AB列
ユーザー 36_bocky36_bocky
提出日時 2018-04-13 23:32:15
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 604 bytes
コンパイル時間 693 ms
コンパイル使用メモリ 69,992 KB
実行使用メモリ 17,556 KB
最終ジャッジ日時 2023-09-10 04:06:55
合計ジャッジ時間 2,165 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 95 ms
17,556 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 16 ms
5,232 KB
testcase_14 WA -
testcase_15 AC 16 ms
5,184 KB
testcase_16 AC 16 ms
5,244 KB
testcase_17 AC 72 ms
11,244 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <utility>
#include <map>
#include <algorithm>

using namespace std;

typedef pair<long long , long long>p;

int main()
{
  long long rui[200001];
  
  map<long long, long long> mp;
  string str;
  long long ans = 0;

  cin >> str;

  for ( long long i = 0; i < str.size(); i++) {
    if (str[i] == 'A' ) {
      rui[i + 1] = rui[i] + 1;
    } else {
      rui[i + 1] = rui[i] - 1;
    }

    if ( mp.count(rui[i + 1]) == 0 ) {
      mp[rui[i + 1]] = i + 1;
    } else {
      ans = max(ans, i + 1 - mp[rui[i + 1]] );
    }
    
  }

  printf("%lld\n", ans);

  return (0);
}
0