結果

問題 No.52 よくある文字列の問題
ユーザー ty70ty70
提出日時 2015-06-09 15:34:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,371 bytes
コンパイル時間 804 ms
コンパイル使用メモリ 97,232 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 03:59:38
合計ジャッジ時間 1,373 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 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 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

set<string> g;
int N;

void dfs (int depth, string curr, string cand ){

	if (depth == N ){
//		cerr << "cand: " << cand << endl;
		g.insert (cand );
		return;
	} // end if

	string next1 = cand, next2 = cand;
	next1 += curr[0];
	dfs (depth + 1, curr.substr(1), next1  );

	next2 += curr[curr.length() - 1];
	dfs (depth + 1, curr.substr(0, curr.length() - 1 ) , next2 );

}

int main()
{
	ios_base::sync_with_stdio(0);
	string S; cin >> S; N = S.length();

	g.clear();
	dfs (0, S, "" );

	cout << g.size() << endl;

	return 0;
}
0