結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー koyumeishi
提出日時 2015-05-22 01:40:00
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 1,267 bytes
コンパイル時間 955 ms
コンパイル使用メモリ 78,276 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-24 11:46:40
合計ジャッジ時間 2,138 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;

int main(){
    int d;
    cin >> d;
    string a,b;
    cin >> a >> b;

    string c = "xxxxxxx";

    string s = c+c;
    s += a;
    s += b;
    s += c+c;

    vector<int> begin;
    vector<int> end;
    int last = -100;
    int tmp = 0;
    for(int i=0; i<s.size(); i++){
        if(s[i] == 'o'){
            if(last == i-1){

            }else{
                begin.push_back(i);

            }
            last = i;
        }else if(last == i-1){
            end.push_back(i-1);
        }
    }

    int ans = 0;
    if(begin.size() == 0){
        ans = d;
    }else{
        ans = max(end.front() - begin.front(), end.back() - begin.back()) + 1 + d;
    }

    for(int i=0; i<begin.size(); i++){
        if(i+1 < begin.size() && begin[i+1] - end[i] - 1 <= d){
            ans = max(ans, end[i+1] - begin[i] + 1);
        }else{
            ans = max(ans, end[i] - begin[i] + 1 + d);
        }
        if(i-1 >= 0 && begin[i] - end[i-1] - 1 > d){
            ans = max(ans, end[i] - begin[i] + 1 + d);
        }
    }

    cout << ans << endl;

    return 0;
}
0