Submission #00133
ソースコード
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | #include<bits/stdc++.h> using namespace std; struct Sc { string s; int cnt; }; string masB; string masE; int main() { char c; for ( int i = 0; i < 3; i++) { for ( int j = 0; j < 3; j++) { cin>> c; masB += c; } } for ( int i = 0; i < 3; i++) { for ( int j = 0; j < 3; j++) { cin>> c; masE += c; } } //cout<< masB <<endl; map<string, bool > memo; queue<Sc> que; que.push((Sc){masB, 0}); while (!que.empty()) { Sc q = que.front(); que.pop(); //cout<< q.s <<endl; if (memo[q.s]) continue ; memo[q.s] = true ; if (q.s == masE) { cout<< q.cnt <<endl; break ; } for ( int i = 0; i < 9; i++) { if (q.s[i] == '@' ) { string s = q.s; if ((i + 1) % 3 == 0) { swap(s[i - 1], s[i]); que.push((Sc){s, q.cnt + 1}); } else if (i % 3 == 1) { swap(s[i - 1], s[i]); que.push((Sc){s, q.cnt + 1}); s = q.s; swap(s[i], s[i + 1]); que.push((Sc){s, q.cnt + 1}); } else { swap(s[i], s[i + 1]); que.push((Sc){s, q.cnt + 1}); } s = q.s; if (0 <= i && i <= 2) { swap(s[i], s[i + 3]); que.push((Sc){s, q.cnt + 1}); } else if (3 <= i && i <= 5) { swap(s[i], s[i - 3]); que.push((Sc){s, q.cnt + 1}); s = q.s; swap(s[i], s[i + 3]); que.push((Sc){s, q.cnt + 1}); } else { swap(s[i], s[i - 3]); que.push((Sc){s, q.cnt + 1}); } } } } return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0005 - Hちゃんのマイブーム |
ユーザー名 | サウンド |
投稿日時 | 2017-08-01 11:21:08 |
言語 | C++11 |
状態 | Accepted |
得点 | 60 |
ソースコード長 | 1523 Byte |
最大実行時間 | 44 ms |
最大メモリ使用量 | 4248 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 60 / 60 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
input07-01.txt | AC | 25 ms | 480 KB |
1
|
input07-02.txt | AC | 17 ms | 564 KB |
1
|
input07-03.txt | AC | 44 ms | 4248 KB |
1
|
input07-04.txt | AC | 11 ms | 680 KB |
1
|
input07-05.txt | AC | 10 ms | 520 KB |
1
|
input07-06.txt | AC | 17 ms | 1260 KB |
1
|
input07-07.txt | AC | 10 ms | 624 KB |
1
|
input07-08.txt | AC | 12 ms | 604 KB |
1
|
input07-09.txt | AC | 20 ms | 660 KB |
1
|
input07-10.txt | AC | 12 ms | 720 KB |
1
|
input07-11.txt | AC | 11 ms | 644 KB |
1
|
input07-12.txt | AC | 13 ms | 612 KB |
1
|
input07-13.txt | AC | 11 ms | 564 KB |
1
|
input07-14.txt | AC | 11 ms | 580 KB |
1
|
input07-15.txt | AC | 12 ms | 672 KB |
1
|