結果

問題 No.1376 Simple LPS Problem
ユーザー leaf_1415
提出日時 2020-10-13 00:48:23
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,074 bytes
コンパイル時間 557 ms
コンパイル使用メモリ 63,000 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-22 19:43:42
合計ジャッジ時間 7,415 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 39 RE * 21
権限があれば一括ダウンロードができます

ソースコード

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 <= 1000);
	
	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 < 1000; i++) s += "010011";
		s = s.substr(0, n);
		cout << s << endl;
	}
	
	return 0;
}
0