結果
| 問題 | No.672 最長AB列 | 
| コンテスト | |
| ユーザー |  ninoinui | 
| 提出日時 | 2020-03-09 20:59:26 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 508 bytes | 
| コンパイル時間 | 1,615 ms | 
| コンパイル使用メモリ | 169,888 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-11-14 06:53:40 | 
| 合計ジャッジ時間 | 2,434 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 7 WA * 9 | 
ソースコード
#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";
}
            
            
            
        