結果

問題 No.52 よくある文字列の問題
ユーザー Mcpu3Mcpu3
提出日時 2019-03-08 12:23:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 749 bytes
コンパイル時間 1,100 ms
コンパイル使用メモリ 81,560 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 04:17:23
合計ジャッジ時間 1,778 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 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 <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

string S;
vector<string> tmp;

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

int main() {
	cin >> S;
	dfs("", S.substr(0, 1), S.substr(1, S.size() - 1));
	dfs("", S.substr(S.size() - 1, 1), S.substr(0, S.size() - 1));
	int ans = 1;
	sort(tmp.begin(), tmp.end());
	for (int i = 1; i < tmp.size(); ++i) {
		if (tmp[i - 1] != tmp[i]) ++ans;
	}
	cout << ans;
}
0