結果

問題 No.1376 Simple LPS Problem
ユーザー k
提出日時 2021-02-17 12:35:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,091 bytes
コンパイル時間 2,005 ms
コンパイル使用メモリ 193,852 KB
最終ジャッジ日時 2025-01-18 21:45:14
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 60
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int calc(const string& s) {
  int ret = 0;
  for (int i = 0; i < s.length(); i++) {
    for (int j = i; j < s.length(); j++) {
      int l = i;
      int r = j;
      while (l < r) {
        if (s[l] != s[r])
          break;
        ++l;
        --r;
      }
      if (l >= r) {
        ret = max(ret, j-i+1);
      }
    }
  }
  return ret;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, k;
  cin >> n >> k;

  if (n < 10) {
    string ret;
    for (int mask = 0; mask < 1<<n; mask++) {
      string s;
      for (int i = 0; i < n; i++) {
        if (mask & 1 << i)
          s += '1';
        else
          s += '0';
      }
      if (calc(s) == k)
        ret = s;
    }

    if (ret.length())
      cout << ret << endl;
    else
      cout << -1 << endl;
    
  } else {
    if (k < 4)
      cout << -1 << endl;
    else {
      string ret(k, '0');
      string t = "101100";
      for (int i = 0; i < n - k; i++) {
        ret += t[i % t.length()];
      }
      cout << ret << endl;
    }
  }
  
  return 0;
}
0