結果
問題 | No.273 回文分解 |
ユーザー |
![]() |
提出日時 | 2016-03-15 02:48:46 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 546 bytes |
コンパイル時間 | 586 ms |
コンパイル使用メモリ | 59,780 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-25 13:36:14 |
合計ジャッジ時間 | 1,646 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#include <iostream>#include <algorithm>#include <string>using namespace std;bool check(const string &str){string tmp = str;reverse(tmp.begin(),tmp.end());if(str == tmp) return true;return false;}int main(){string s;cin >> s;int n = s.size();if(n == 2 || count(s.begin(),s.end(),s[0]) == n) cout << --n << endl;else{int ans = 1;for(int i = 0;i < n;i++) for(int j = 1;j <= n - i;j++) if(check(s.substr(i,j))) ans = max(ans,j);if(ans == n) ans -= 2;cout << ans << endl;}}