結果
問題 |
No.170 スワップ文字列(Easy)
|
ユーザー |
![]() |
提出日時 | 2017-01-28 18:27:09 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 288 ms / 5,000 ms |
コード長 | 711 bytes |
コンパイル時間 | 1,091 ms |
コンパイル使用メモリ | 83,372 KB |
実行使用メモリ | 7,040 KB |
最終ジャッジ日時 | 2024-12-23 21:15:11 |
合計ジャッジ時間 | 3,012 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include <iostream> #include <set> #include <queue> using namespace std; int main() { string s; cin >> s; set<string> used; used.insert(s); queue<string> que; que.push(s); int N = s.size(), cnt = 0; while (!que.empty()) { string n = que.front(); que.pop(); for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { swap(n[i], n[j]); if (used.count(n) == 0) { used.insert(n); cnt++; que.push(n); } swap(n[i], n[j]); } } } cout << cnt << endl; return 0; }