結果

問題 No.52 よくある文字列の問題
ユーザー memmemmimemmemmi
提出日時 2018-06-26 19:27:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 835 bytes
コンパイル時間 1,740 ms
コンパイル使用メモリ 99,020 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 04:15:23
合計ジャッジ時間 1,417 ms
ジャッジサーバーID
(参考情報)
judge10 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;

string str;
set<string> cnt;

int dfs(int n, string x, string rest) {
	if (n == 0) {
		if (cnt.count(x) == 0) {
			cnt.insert(x);
			return 1;
		}
		else return 0;
	}
	int ans = 0;
	ans += dfs(n - 1, x + rest[0], rest.substr(1, n - 1));
	ans += dfs(n - 1, x + rest[n - 1], rest.substr(0, n - 1));
	return ans;
}

int main() {
	cin >> str;
	int n = str.size();
	cout << dfs(n, "", str) << endl;
	return 0;
}
0