結果

問題 No.170 スワップ文字列(Easy)
ユーザー moti
提出日時 2015-04-03 11:13:04
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 83 ms / 5,000 ms
コード長 411 bytes
コンパイル時間 1,551 ms
コンパイル使用メモリ 165,500 KB
実行使用メモリ 9,216 KB
最終ジャッジ日時 2024-12-23 00:21:46
合計ジャッジ時間 2,559 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

int N;
set<string> st;
int ans;

void dfs(std::string& s) {
	st.insert(s);
	ans++;
	rep(i, N-1) {
		swap(s[i], s[i+1]);
		if(!st.count(s)) { dfs(s); }
		swap(s[i], s[i+1]);
	}
}


int main() {

	string S;
	cin >> S;
	N = S.size();

	dfs(S);

	cout << st.size() -1 << endl;

	
	return 0;
}
0