結果
| 問題 |
No.52 よくある文字列の問題
|
| コンテスト | |
| ユーザー |
ty70
|
| 提出日時 | 2015-06-09 15:44:18 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,549 bytes |
| コンパイル時間 | 843 ms |
| コンパイル使用メモリ | 97,064 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-22 05:21:29 |
| 合計ジャッジ時間 | 1,381 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 |
ソースコード
#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()
/*
No.52 よくある文字列の問題
解法:DFS(深さ優先探索)
深さ優先探索は、必ず終了条件を付ける事。(でないと無限ループで返ってこなくなる。)
*/
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
set<string> all;
void dfs (int depth, string curr, string cand ){
if (curr.empty() ){ // 終了条件
all.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;
all.clear();
dfs (0, S, "" );
cout << all.size() << endl;
return 0;
}
ty70