結果
| 問題 |
No.559 swapAB列
|
| コンテスト | |
| ユーザー |
femto
|
| 提出日時 | 2017-08-25 22:25:14 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 509 bytes |
| コンパイル時間 | 1,741 ms |
| コンパイル使用メモリ | 182,668 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-15 15:57:05 |
| 合計ジャッジ時間 | 2,207 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 7 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s, goal;
cin >> s;
goal = s;
sort(goal.begin(), goal.end());
map<string, int> m;
m[s] = 0;
queue<string> q;
q.push(s);
while(q.size()) {
s = q.front();
q.pop();
int d = m[s];
for(int i = 0; i < s.size() - 1; i++) {
string ns = s;
swap(ns[i], ns[i + 1]);
if(m.count(ns)) continue;
m[ns] = d + 1;
q.push(ns);
}
}
cout << m[goal] << endl;
}
femto