結果
| 問題 | 
                            No.238 Mr. K's Another Gift
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2018-09-02 16:02:12 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,023 bytes | 
| コンパイル時間 | 831 ms | 
| コンパイル使用メモリ | 66,432 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-01 19:26:27 | 
| 合計ジャッジ時間 | 3,769 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 39 WA * 1 | 
ソースコード
#include<iostream>
using namespace std;
bool isPalindrome(string s){
    int n = s.length();
    for(int i = 0; i < n/2; i++){
        if(s[i] != s[n-1-i])    return false;
    }
    return true;
}
int main(){
    string s;
    cin >> s;
    
    int n = s.length();
    if(isPalindrome(s)){
        s.insert(s.begin() + n/2, s[n/2]);
    }else{
        string ans = "";
        
        int diffpos;
        for(diffpos = 0;; diffpos++)    if(s[diffpos] != s[n-1-diffpos])    break;
        
        s.insert(s.begin() + diffpos, 'a');
        for(int i = 0; i < 25; i++){
            if(isPalindrome(s)) ans = s;
            s[diffpos]++;
        }
        s.erase(s.begin()+diffpos);
        s.insert(s.begin() + n - diffpos, 'a');
        for(int i = 0; i < 25; i++){
            if(isPalindrome(s)) ans = s;
            s[n-diffpos]++;
        }
        s.erase(s.begin() + n - diffpos); // needless
        if(ans != "")   s = ans;
        else            s = "NA";
    }
    cout << s << endl;
    return 0;
}