結果
| 問題 | 
                            No.273 回文分解
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2015-10-03 01:46:44 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 793 bytes | 
| コンパイル時間 | 650 ms | 
| コンパイル使用メモリ | 70,524 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-25 13:30:34 | 
| 合計ジャッジ時間 | 1,773 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / 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 right) {
	while (left < right) {
		if (s[left] != s[right])
			return false;
		left++;
		right--;
	}
	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);
					break;
				}
			}
			right--;
		}
	}
	if (ans == s.size())
		ans -= 2;
	cout << ((ans == 0) ? 1 : ans) << endl;
}