結果

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

ソースコード

diff #

#line 1 "main.cpp"
#include <iostream>
#include <set>
#include <string>

using namespace std;

const set<int> ones{0, 2, 3};

bool pali(const string& s) {
    return s == string(s.rbegin(), s.rend());
}

void solve() {
    int n, k;
    cin >> n >> k;

    if (n <= 15) {
        for (int b = 0; b < (1 << n); ++b) {
            string s(n, '0');
            for (int i = 0; i < n; ++i) {
                if ((b >> i) & 1) s[i] = '1';
            }

            int f = 0;
            for (int l = 0; l < n; ++l) {
                for (int len = 1; l + len <= n; ++len) {
                    if (pali(s.substr(l, len))) f = max(f, len);
                }
            }

            if (f == k) {
                cout << s << "\n";
                return;
            }
        }

        cout << "-1\n";
        return;
    }

    if (k <= 3) {
        cout << "-1\n";
        return;
    }

    string s(n, '0');
    for (int i = 0; i + k < n; ++i) {
        if (ones.count(i % 6)) s[i + k] = '1';
    }
    cout << s << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
0