結果

問題 No.672 最長AB列
ユーザー どららどらら
提出日時 2018-04-13 22:31:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 863 bytes
コンパイル時間 1,691 ms
コンパイル使用メモリ 169,276 KB
実行使用メモリ 5,392 KB
最終ジャッジ日時 2023-09-10 00:03:36
合計ジャッジ時間 2,634 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;

  vector<pair<int,int>> v;
  char prev = '.';
  int cnt = 0;
  rep(i,s.size()){
    if(s[i] != prev){
      if(prev != '.') v.push_back(make_pair(prev,cnt));
      prev = s[i];
      cnt = 1;
    }else{
      cnt++;
    }
  }
  v.push_back(make_pair(prev,cnt));

  int ret = 0;
  rep(i,v.size()-1){
    ret = max(ret, min(v[i].second, v[i+1].second));
  }
  REP(i,1,v.size()-1){
    if(v[i].second <= v[i-1].second + v[i+1].second){
      ret = max(ret, v[i].second);
    }
  }
  
  cout << ret*2 << endl;
  
  return 0;
}

0