Submission #00063
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #include <bits/stdc++.h> using namespace std; int main() { int my[] = {1, 0, -1, 0}; int mx[] = {0, 1, 0, -1}; string s, t; map < string , int > mp; queue < string > que; for ( int i = 0; i < 9; i++) { char a; cin >> a; s.push_back(a); } for ( int i = 0; i < 9; i++) { char a; cin >> a; t.push_back(a); } mp[s] = 0; que.push(s); while (!que.empty()) { string h = que.front(); que.pop(); string w; for ( int ii = 0; ii < 9; ii++) { int i = ii / 3, j = ii % 3; for ( int k = 0; k < 4; k++) { int ny = i + my[k], nx = j + mx[k]; if (0 <= ny && 0 <= nx && ny < 3 && nx < 3 && h[ny * 3 + nx] == '@' ) { w = h; swap(w[i * 3 + j], w[ny * 3 + nx]); if (mp.find(w) == mp.end()) { mp[w] = mp[h] + 1; que.push(w); } } } } } cout << mp[t] << endl; return (0); } |
ステータス
項目 | データ |
---|---|
問題 | 0005 - Hちゃんのマイブーム |
ユーザー名 | Eraim Unit |
投稿日時 | 2017-08-01 10:36:45 |
言語 | C++11 |
状態 | Accepted |
得点 | 60 |
ソースコード長 | 927 Byte |
最大実行時間 | 297 ms |
最大メモリ使用量 | 15412 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 60 / 60 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
input07-01.txt | AC | 262 ms | 15200 KB |
1
|
input07-02.txt | AC | 264 ms | 15152 KB |
1
|
input07-03.txt | AC | 269 ms | 15212 KB |
1
|
input07-04.txt | AC | 265 ms | 15288 KB |
1
|
input07-05.txt | AC | 261 ms | 15228 KB |
1
|
input07-06.txt | AC | 273 ms | 15308 KB |
1
|
input07-07.txt | AC | 283 ms | 15384 KB |
1
|
input07-08.txt | AC | 260 ms | 15200 KB |
1
|
input07-09.txt | AC | 281 ms | 15256 KB |
1
|
input07-10.txt | AC | 284 ms | 15208 KB |
1
|
input07-11.txt | AC | 280 ms | 15164 KB |
1
|
input07-12.txt | AC | 286 ms | 15220 KB |
1
|
input07-13.txt | AC | 297 ms | 15292 KB |
1
|
input07-14.txt | AC | 254 ms | 15352 KB |
1
|
input07-15.txt | AC | 256 ms | 15412 KB |
1
|