結果

問題 No.672 最長AB列
ユーザー 36_bocky
提出日時 2018-04-13 23:23:09
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 668 bytes
コンパイル時間 696 ms
コンパイル使用メモリ 69,760 KB
実行使用メモリ 14,592 KB
最終ジャッジ日時 2024-06-27 19:35:30
合計ジャッジ時間 2,266 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

typedef pair<int , int>p;

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

  cin >> str;

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

    rui[i + 1].second = i + 1;

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

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

  return (0);
}
0