結果

問題 No.2234 palindromer
ユーザー umimelumimel
提出日時 2023-03-03 22:07:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,455 bytes
コンパイル時間 1,666 ms
コンパイル使用メモリ 170,076 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 02:14:24
合計ジャッジ時間 2,408 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 4 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (int i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second

const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1LL << 60;
const ll MAX_N = 2e5;

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

    ll n = (ll)s.size();
    ll ans_len = INF;
    string ans_str = "";
    for(ll i=0; i<n; i++) for(ll j=i; j<n; j++){
        //s[i], ..., s[j]が回文
        string t = "";
        for(ll k=i; k<=j; k++) t+=s[k];
        bool check1 = true;
        for(ll k=0; k<(ll)t.size()/2; k++) if(t[k]!=t[(ll)t.size()-1-k]) check1 = false;

        string pre="", post="";
        for(ll k=j+1; k<n; k++) post+=s[k];
        for(ll k=i-1; k>=0; k--) pre+=s[k];
        bool check2 = true;
        if((ll)pre.size() < (ll)post.size()) continue;
        for(ll k=0; k<(ll)post.size(); k++){
            if(pre[k]!=post[k]){
                check2 = false;
            }
        }

        if(check1 && check2){
            string tmp = s;
            for(ll k=i-1-(ll)post.size(); k>=0; k--) tmp+=s[k];
            if((ll)tmp.size() < ans_len){
                ans_len = (ll)tmp.size();
                ans_str = tmp;
            }
        }
    }

    cout << ans_str << endl;
}
0