結果

問題 No.52 よくある文字列の問題
コンテスト
ユーザー Mcpu3
提出日時 2019-03-08 13:23:55
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 606 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 469 ms
コンパイル使用メモリ 84,384 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-10 11:25:15
合計ジャッジ時間 1,202 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

set<string> ans;

void dfs(string tmp1, string tmp2, string tmp3) {
	if (tmp1.size() == 0) ans.insert(tmp2 + tmp3);
	else if (tmp1.size() == 1) dfs("", tmp2 + tmp3, tmp1.substr(0, 1));
	else {
		dfs(tmp1.substr(0, tmp1.size() - 1), tmp2 + tmp3, tmp1.substr(tmp1.size() - 1, 1));
		dfs(tmp1.substr(1, tmp1.size() - 1), tmp2 + tmp3, tmp1.substr(0, 1));
	}
}

int main() {
	string S;
	cin >> S;
	dfs(S.substr(0, S.size() - 1), "", S.substr(S.size() - 1, 1));
	dfs(S.substr(1, S.size() - 1), "", S.substr(0, 1));
	cout << ans.size();
}
0