結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー ty70ty70
提出日時 2015-05-28 16:10:40
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,130 bytes
コンパイル時間 992 ms
コンパイル使用メモリ 98,940 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-21 14:34:27
合計ジャッジ時間 2,147 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
testcase_36 AC 1 ms
5,376 KB
testcase_37 AC 1 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 1 ms
5,376 KB
testcase_40 AC 1 ms
5,376 KB
testcase_41 WA -
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 1 ms
5,376 KB
testcase_44 AC 1 ms
5,376 KB
testcase_45 AC 1 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 1 ms
5,376 KB
testcase_48 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int MAX_V = 50;

int par[MAX_V];	// 親

// n 要素で初期化
void uf_init (int n ){
	rep (i, n ){
		par[i] = i;
	} // end rep
}
	
// 木の根を求める
int uf_find (int x ){
	if (par[x] == x )
		 return x;
	else
		return par[x] = uf_find (par[x] );
}
		
// x と y の属する集合を併合
void uf_unite (int x, int y ){
	x = uf_find (x );
	y = uf_find (y );

	if (x == y ){
		return;
	}else
	if (x < y ){
		par[y] = x;
	}else{	// if x > y
		par[x] = y;
	} // end if
}

bool uf_same (int x, int y ){
	return uf_find (x) == uf_find (y );
}

int uf_size(void ){
	set<int> res; res.clear();
	rep (i, MAX_V ){
		res.insert (uf_find(par[i] ) );
	} // end rep

	set<int>::iterator it = res.begin();

	return res.size();
}


const string weekly = "xxxxxxx";
int cnt[50];

int max_holiday (string s ){
	memset (cnt, 0, sizeof (cnt ) );
	cnt[0] = (s[0] == 'o' );
	int n = s.length();

	for (int i = 1; i < n; i++ ){
		if (s[i] == 'o' )
			cnt[i] = cnt[i-1] + 1;
		else
			cnt[i] = 0;
	} // end for

	int res = 0;
	rep (i, n ) res = max (res, cnt[i] );

	return res;
}

/*
	OK!
	xxxxooooxxxx
	--oooooo----

	NG!
	xxxxooooxxxx
	---oooooo---

	OK!
	ooooxxxxoooo
	---oooooo---

	NG!
	xxxxooooxoxx
	---ooooooo--

	×が連続している部分は OK。
	×が離れて存在する部分は NG。
			
*/

bool is_concated (string s ){
	int n = s.length();

	if (n == 1 ) return true;

	uf_init (n );
	for (int i = 1; i < n; i++ ){
		if (s[i-1] == 'x' && s[i-1] == s[i] )
			uf_unite (i-1, i );
	} // end for

	int res = uf_size();
//	cerr << res << endl;

	return (res == 1 ); 
}

string replace (string s, string t, int p ){

	string u = "";
	if (!is_concated (s.substr(p, t.length() ) ) ) return u;
	u = s;

	rep (i, t.length() ) u[p+i] = t[i];

	return u;   
}	

int main()
{
	ios_base::sync_with_stdio(0);
	int D; cin >> D;
	string c1; cin >> c1;
	string c2; cin >> c2;
	string s = "";
	rep (i, 2 ) s += weekly;
	s += c1; s += c2;
 	rep (i, 2 ) s += weekly;

	string t = "";
	rep (i, D ) t += 'o';

	int res = 0;
	rep (i, s.length() - t.length() + 1 ){
		string u = replace (s, t, i );
		bool ok = (!u.empty() );
		int curr = 0;
		if (ok ){
//			cerr << u << endl;
			curr = max_holiday (u );
		} // end if
		res = max (res, curr );
	} // end rep
	cout << res << endl;

	return 0;
}
0