結果

問題 No.238 Mr. K's Another Gift
ユーザー codershifthcodershifth
提出日時 2016-05-01 17:41:37
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,529 bytes
コンパイル時間 1,760 ms
コンパイル使用メモリ 164,852 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 08:22:30
合計ジャッジ時間 7,359 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 3 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 2 ms
6,940 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 3 ms
6,940 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 2 ms
6,944 KB
testcase_38 AC 2 ms
6,944 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RANGE(vec) (vec).begin(),(vec).end()

using namespace std;


class MrKsAnotherGift
{
public:
    void solve(void)
    {
        string s;
        cin>>s;

        int N = s.length();
        string ans[2];
        bool inserted = false;
        for (int i = 0; i < N/2; ++i)
        {
            if ( s[i] != s[N-1-i] )
            {
                if ( inserted )
                {
                    cout<<"NA"<<endl;
                    return;
                }
                ans[0] = s.substr(0,i) + string(1,s[N-1-i]) + s.substr(i,N);
                ans[1] = s.substr(0,N-1-i) + string(1,s[i]) + s.substr(N-1-i,N);
                inserted = true;
            }
        }
        if ( !inserted )
        {
            cout<<s<<endl;
            return;
        }
        bool ok[2] = {true,true};
        for (int i = 0; i < N; ++i)
        {
            for (int j = 0; j < 2; ++j)
            {
                if ( ans[i] != ans[N-1-i] )
                    ok[j] = false;
            }
        }
        if ( ok[0] )
            cout<<ans[0]<<endl;
        else if ( ok[1] )
            cout<<ans[1]<<endl;
        else
            cout<<"NA"<<endl;
    }
};

#if 1
int main(int argc, char *argv[])
{
        ios::sync_with_stdio(false);
        auto obj = new MrKsAnotherGift();
        obj->solve();
        delete obj;
        return 0;
}
#endif
0