結果

問題 No.1376 Simple LPS Problem
ユーザー leaf_1415
提出日時 2020-11-12 19:25:37
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,078 bytes
コンパイル時間 1,333 ms
コンパイル使用メモリ 62,940 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-22 19:42:54
合計ジャッジ時間 3,224 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 60
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <fstream>
#include <cassert>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

int n, k;

int calc(string &s)
{
	int ret = 0;
	for(int i = 0; i < s.size(); i++){
		for(int j = 0; ; j++){
			if(i+j >= s.size() || i-j < 0) break;
			if(s[i+j] != s[i-j]) break;
			ret = max(ret, 2*j+1);
		}
	}
	for(int i = 1; i < s.size(); i++){
		if(s[i-1] != s[i]) continue;
		for(int j = 0; ; j++){
			if(i+j >= s.size() || i-j-1 < 0) break;
			if(s[i+j] != s[i-j-1]) break;
			ret = max(ret, 2*j+2);
		}
	}
	return ret;
}

int main()
{
	cin >> n >> k;
	assert(1 <= k && k <= n && n <= 100000);
	
	if(n <= 8){
		int N = 1 << n;
		for(int i = 0; i < N; i++){
			string s;
			for(int j = 0; j < n; j++) s += ((i>>j)&1) + '0';
			if(calc(s) == k){
				cout << s << endl;
				return 0;
			}
		}
		cout << -1 << endl;
	}
	else{
		if(k < 4){
			cout << -1 << endl;
			return 0;
		}
		string s;
		for(int i = 0; i < k; i++) s += '1';
		for(int i = 0; i < 100000; i++) s += "010011";
		s = s.substr(0, n);
		cout << s << endl;
	}
	
	return 0;
}
0