結果
| 問題 | No.204 ゴールデン・ウィーク(2) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-06-08 21:46:21 |
| 言語 | C++11(old_compat) (gcc 12.4.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 1,000 ms |
| コード長 | 1,039 bytes |
| 記録 | |
| コンパイル時間 | 1,357 ms |
| コンパイル使用メモリ | 173,368 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2026-03-08 16:02:43 |
| 合計ジャッジ時間 | 2,269 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 46 |
ソースコード
#include <iostream>
#include <algorithm>
using namespace std;
string conv(string str){
while(str[0] == 'x')
str = str.substr(1, str.size() - 1);
while(str[str.size() - 1] == 'x')
str = str.substr(0, str.size() - 1);
return str;
}
int solve(string str, int d){
str = conv(str);
if(str.size() == 0)
return d;
vector<int> vec;
int tmp = 1;
for(int i = 1; i < str.size(); i++){
if(str[i] == str[i - 1])
tmp++;
else {
vec.push_back(tmp);
tmp = 1;
}
}
vec.push_back(tmp);
if(vec.size() == 1)
return vec[0] + d;
int result;
result = vec[0] + d;
result = max(result, vec[vec.size() - 1] + d);
for(int i = 1; i < vec.size(); i += 2){
if(vec[i] <= d)
result = max(result, vec[i - 1] + vec[i] + vec[i + 1]);
else {
result = max(result, vec[i - 1] + d);
result = max(result, vec[i + 1] + d);
}
}
return result;
}
int main(){
int d;
cin >> d;
string a, b;
cin >> a >> b;
string str = a + b;
cout << solve(str, d) << endl;
}