結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー h_noson
提出日時 2016-02-18 16:52:42
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 928 bytes
コンパイル時間 941 ms
コンパイル使用メモリ 64,480 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-24 11:51:23
合計ジャッジ時間 1,961 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define RREP(i,s,e) for (int i = e-1; i >= s; i--)
#define rrep(i,n) RREP(i,0,n)
#define REP(i,s,e) for (int i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)

int main() {
    int d;
    string s,t;
    cin >> d;
    rep (i,d) s.push_back('x');
    cin >> t;
    s += t;
    cin >> t;
    s += t;
    rep (i,d) s.push_back('x');

    vector<int> a{0};
    char now = 'x';
    int cnt = 0;
    int ans = 0;
    rep (i,14+d*2) {
        if (s[i] == now)
            cnt++;
        else {
            a.push_back(cnt);
            cnt = 1;
            now = s[i];
        }
    }
    a.push_back(cnt);
    a.push_back(0);
    for (int i = 1; i < a.size()-1; i+=2) {
        if (a[i] > d)
            ans = max(ans, d + max(a[i-1],a[i+1]));
        else
            ans = max(ans, a[i-1] + a[i] + a[i+1]);
    }
    cout << ans << endl;
    return 0;
}
0