結果

問題 No.52 よくある文字列の問題
コンテスト
ユーザー Dadarithm
提出日時 2015-10-11 09:48:29
言語 C++11
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 5,000 ms
+ 496µs
コード長 415 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 401 ms
コンパイル使用メモリ 82,480 KB
実行使用メモリ 9,804 KB
最終ジャッジ日時 2026-09-02 05:11:00
合計ジャッジ時間 1,498 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <set>
#include <string>
using namespace std;

string S; set<string> memo;

void dfs(string s, string ans)
{
	if (s.empty())
	{
		memo.insert(ans);
		return;
	}

	char c = s.front();
	s.erase(s.begin(), s.begin() + 1);
	dfs(s, ans + c);
	s = c + s;

	c = s.back();
	s.erase(s.end() - 1, s.end());
	dfs(s, ans + c);
}

int main()
{
	cin >> S;

	dfs(S, "");
	cout << memo.size() << endl;
}
0