結果
問題 | No.52 よくある文字列の問題 |
ユーザー |
|
提出日時 | 2019-03-08 12:23:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 749 bytes |
コンパイル時間 | 1,309 ms |
コンパイル使用メモリ | 81,732 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-22 05:38:23 |
合計ジャッジ時間 | 1,545 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 11 |
ソースコード
#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; }