結果

問題 No.672 最長AB列
ユーザー ninoinuininoinui
提出日時 2020-03-09 20:59:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 508 bytes
コンパイル時間 1,520 ms
コンパイル使用メモリ 165,160 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 17:23:12
合計ジャッジ時間 2,330 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  string S;
  cin >> S;
  int N = S.size();
  vector<int> V(N);
  S.insert(S.size(), " ");
  for (int i = 0, cnt = 1; i < N; i++) {
    if (S.at(i) != S.at(i + 1)) V.at(i) = cnt, cnt = 1;
    else cnt++;
  }
  for (int i = N - 1; i >= 0; i--) {
    if (!V.at(i)) V.at(i) = V.at(i + 1);
  }
  int ans = 0;
  for (int i = 0; i + 1 < N; i++) {
    if (S.at(i) != S.at(i + 1)) ans = max(ans, min(V.at(i), V.at(i + 1)) * 2);
  }
  cout << ans << "\n";
}
0