結果
問題 |
No.273 回文分解
|
ユーザー |
|
提出日時 | 2015-10-31 21:41:06 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,632 bytes |
コンパイル時間 | 888 ms |
コンパイル使用メモリ | 92,768 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-25 13:32:03 |
合計ジャッジ時間 | 1,931 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#include <iostream> #include <string> #include <vector> #include <queue> #include <stack> #include <map> #include <algorithm> #include <numeric> #include <functional> #include <set> #include <sstream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cctype> #include <climits> #include <fstream> #include <bitset> #include <time.h> #define ll long long #define FOR(i,a,b) for(int i= (a); i<((int)b); ++i) #define RFOR(i,a) for(int i=(a); i >= 0; --i) #define FOE(i,a) for(auto i : a) #define ALL(c) (c).begin(), (c).end() #define DUMP(x) cerr << #x << " = " << (x) << endl; #define SUM(x) std::accumulate(ALL(x), 0L) #define EPS 1e-14 using namespace std; set<string> palindromes(string s) { set<string> palindromes; for (int i = 0; i < s.size(); ++i) { // iを中心とした回文 int left = i; int right = i; while (0 <= left && right < s.size() && s[left] == s[right]) { palindromes.insert(s.substr(left, right - left + 1)); left--; right++; } // iとi + 1を中心とした回文 left = i; right = i + 1; while (0 <= left && right < s.size() && s[left] == s[right]) { palindromes.insert(s.substr(left, right - left + 1)); left--; right++; } } return palindromes; } int main(int argc, char *argv[]) { string s; cin >> s; int ans = 0; FOE(p, palindromes(s)) { if (p.size() != s.size()) { ans = max<int>(ans, p.size()); } } cout << ans << endl; return 0; }