結果

問題 No.2234 palindromer
コンテスト
ユーザー hiro71687k
提出日時 2023-03-05 18:38:18
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 824 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,999 ms
コンパイル使用メモリ 277,204 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-29 20:22:28
合計ジャッジ時間 3,839 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
ld pie=3.14159265359;
ll inf=10000000000000001;
ll mod=998244353;
int main(){
	string s;
	cin >> s;
	bool ok=true;
	ll y=s.size();
	for (ll i = 0; i < y; i++)
	{
		if (s[i]!=s[y-1-i])
		{
			ok=false;
		}
	}
	if (ok)
	{
		cout << s << endl;
		return 0;
	}
	vector<string>ans;
	for (ll i =0; i < s.size(); i++)
	{
		string t=s;
		for (ll j = i; j >=0; j--)
		{
			t.push_back(s[j]);
		}
		bool ok=true;
		ll x=t.size();
		for (ll j = 0; j < x; j++)
		{
			if (t[j]!=t[x-j-1])
			{
				ok=false;
				break;
			}
		}
		if (ok)
		{
			ans.push_back(t);
		}
	}
	string a=s+s+s;
	for (ll i = 0; i < ans.size(); i++)
	{
		if (ans[i].size()<a.size())
		{
			a=ans[i];
		}
	}
	cout << a << endl;
}
0