結果

問題 No.2234 palindromer
ユーザー hiro71687k
提出日時 2023-03-05 18:38:18
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 824 bytes
コンパイル時間 4,297 ms
コンパイル使用メモリ 252,868 KB
最終ジャッジ日時 2025-02-11 05:34:20
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#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