結果

問題 No.1617 Palindrome Removal
ユーザー CleyLCleyL
提出日時 2023-07-06 10:48:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 684 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 77,148 KB
実行使用メモリ 5,164 KB
最終ジャッジ日時 2023-09-27 11:57:38
合計ジャッジ時間 2,309 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
4,380 KB
testcase_01 AC 26 ms
5,156 KB
testcase_02 AC 23 ms
4,380 KB
testcase_03 AC 24 ms
4,380 KB
testcase_04 AC 25 ms
5,164 KB
testcase_05 AC 21 ms
4,376 KB
testcase_06 AC 18 ms
5,120 KB
testcase_07 AC 11 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 41 ms
4,380 KB
testcase_11 AC 35 ms
4,376 KB
testcase_12 AC 43 ms
5,092 KB
testcase_13 AC 46 ms
5,072 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>
using namespace std;
int main(){
  string s;cin>>s;
  if(s.size() % 2 == 1){
    set<char> x;
    for(int i = 0; s.size() > i; i++){
      if(s[i] != s[s.size()-1-i]){
        cout << s.size() << endl;
        return 0;
      }
      x.insert(s[i]);
    }
    if(x.size() < 2 || s.size()-2 == 1)cout << -1 << endl;
    else cout << (int)s.size()-2 << endl;
  }else{
    set<char> x;
    for(int i = 0; s.size() > i; i++){
      if(s[i] != s[s.size()-1-i]){
        cout << s.size() << endl;
        return 0;
      }
      if(i != s.size()-i-1)x.insert(s[i]);
    }
    if(x.size() < 2)cout << 0 << endl;
    else cout << s.size()-2 << endl;

  }
}
0