Submission #00045
ソースコード
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 | #include<bits/stdc++.h> using namespace std; struct edge { int to, cost; }; typedef pair< int , int > Pi; const int INF = 1 << 30; int h, w; int sx, sy, gx, gy; int n; Pi mas[31][31]; int m; int bit[31][31]; const int dy[] = {0, 0, 1, 0, -1}, dx[] = {0, 1, 0, -1, 0}; bool used[31][31][5][1 << 10]; bool rec( int x, int y, int d, int bits) { if (x < 0 || x >= w || y < 0 || y >= h) return ( false ); if (used[x][y][d][bits]++) return ( false ); if (x == gx && y == gy) return ( true ); int ret = 0; if (d == 0) { for ( int i = 1; i < 5; i++) { if (rec(x + dx[i], y + dy[i], d, bits)) return ( true ); } return ( false ); } else { if (mas[y][x] == Pi(-1, -1)) { return (rec(x - dx[d], y - dy[d], 0, bits)); } if (mas[y][x] != Pi(INF, INF)) { Pi prev = Pi(INF, INF); swap(prev, mas[y][x]); if (rec(prev.first, prev.second, 0, bits|(1 << bit[y][x]))) return ( true ); swap(prev, mas[y][x]); return ( false ); } return (rec(x + dx[d], y + dy[d], d, bits)); } } int main() { fill_n(*mas, 31 * 31, make_pair(INF, INF)); cin >> h >> w; cin >> sx >> sy >> gx >> gy; cin >> n; int tail = 0; for ( int i = 0; i < n; i++) { int a, b; cin >> a >> b; mas[b][a] = make_pair(-1, -1); } cin >> m; for ( int i = 0; i < m; i++) { int ax, ay, bx, by; cin >> ax >> ay >> bx >> by; if (mas[ay][ax] == make_pair(-1, -1)) continue ; if (mas[by][bx] == make_pair(-1, -1)) continue ; mas[ay][ax] = make_pair(by, bx); mas[by][bx] = make_pair(ay, ax); bit[ay][ax] = tail++; bit[by][bx] = tail++; } if (rec(sx, sy, 0, 0)) puts ( "OK" ); else puts ( "NO" ); } |
ステータス
項目 | データ |
---|---|
問題 | 0003 - 滑った故の結末 |
ユーザー名 | ei1333 |
投稿日時 | 2015-09-16 17:55:05 |
言語 | C++11 |
状態 | Wrong Answer |
得点 | 0 |
ソースコード長 | 1729 Byte |
最大実行時間 | 25 ms |
最大メモリ使用量 | 716 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 0 / 100 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
dfs-b_in1.txt | WA | 21 ms | 472 KB |
1
|
dfs-b_in2.txt | AC | 23 ms | 648 KB |
1
|
dfs-b_in3.txt | AC | 22 ms | 568 KB |
1
|
dfs-b_in4.txt | AC | 25 ms | 628 KB |
1
|
dfs-b_in5.txt | AC | 18 ms | 576 KB |
1
|
dfs-b_in6.txt | AC | 15 ms | 644 KB |
1
|
dfs-b_in7.txt | AC | 21 ms | 688 KB |
1
|
dfs-b_in8.txt | WA | 17 ms | 600 KB |
1
|
dfs-b_in9.txt | AC | 18 ms | 548 KB |
1
|
dfs-b_in10.txt | AC | 16 ms | 660 KB |
1
|
dfs-b_in11.txt | AC | 20 ms | 716 KB |
1
|