結果
| 問題 |
No.273 回文分解
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-10-02 14:47:08 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 768 bytes |
| コンパイル時間 | 679 ms |
| コンパイル使用メモリ | 71,168 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-25 13:30:26 |
| 合計ジャッジ時間 | 1,653 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
bool is_roop(vector<char> s, int left, int tail) {
while (left < tail) {
if (s[left] != s[tail])
return false;
left++;
tail--;
}
return true;
}
int main(void) {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout << std::fixed;
vector<char> s;
int ans = 1;
char c;
while (cin >> c)
s.push_back(c);
int tail = s.size() - 1;
for (int left = 0; left < tail; left++) {
int right = tail;
while (left < right) {
if (s[left] == s[right]) {
if (is_roop(s, left, right))
ans = max(ans, right - left + 1);
}
right--;
}
}
if (ans == s.size())
ans -= 2;
cout << ((ans == 0) ? 1 : ans) << endl;
}