結果
| 問題 |
No.1376 Simple LPS Problem
|
| コンテスト | |
| ユーザー |
merom686
|
| 提出日時 | 2021-02-05 22:47:52 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,223 bytes |
| コンパイル時間 | 740 ms |
| コンパイル使用メモリ | 92,420 KB |
| 最終ジャッジ日時 | 2025-01-18 12:48:01 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 60 |
コンパイルメッセージ
main.cpp: In function ‘int f(char*, int)’:
main.cpp:24:1: warning: control reaches end of non-void function [-Wreturn-type]
24 | }
| ^
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;
int f(char *p, int n) {
for (int k = n; k > 0; k--) {
for (int i = 0; i < n - k + 1; i++) {
int i1 = i + k - 1, b = 1;
for (int j = 0; j < k / 2; j++) {
if (p[i + j] != p[i1 - j]) {
b = 0;
break;
}
}
if (b) return k;
}
}
}
void g(int n, int t) {
char p[100] = {};
p[0] = '0';
for (int k = 0; k < 1 << (n - 1); k++) {
for (int i = 1; i < n; i++) {
p[i] = '0' + (k >> (i - 1) & 1);
}
if (f(p, n) == t) {
cout << p << endl;
return;
}
}
cout << -1 << endl;
}
int main() {
int n, k;
cin >> n >> k;
if (n < 10) {
g(n, k);
quick_exit(0);
}
if (k < 4) {
cout << -1 << endl;
quick_exit(0);
}
for (int i = 0; i < k; i++) {
cout << '0';
}
for (int i = 0; i < n - k; i++) {
cout << "101100"[i % 6];
}
cout << endl;
return 0;
}
merom686