Submission #00032
ソースコード
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 92 93 94 95 96 97 98 99 100 101 | #include<bits/stdc++.h> #define F first #define S second #define INF (1<<30) using namespace std; typedef pair< int , int > P; map<P, int > mem; //0 未達 1 可能 2 不可能 bool dfs( int x, int y); int h,w; int sx,sy,gx,gy; int n,m; int a,b,c,d; char maps[101][101]; P ana[101][101]; int dx[4]={0,1,0,-1}; int dy[4]={1,0,-1,0}; main(){ for ( int i=0;i<=50;i++){ for ( int j=0;j<=50;j++){ maps[i][j]= '.' ; ana[i][j]=P(-1,-1); } } cin>>h>>w; //0から cin>>sx>>sy>>gx>>gy; maps[gy][gx]= 'G' ; cin>>n; for ( int i=0;i<n;i++){ cin>>a>>b; maps[b][a]= '@' ; } cin>>m; for ( int i=0;i<m;i++){ cin>>a>>b>>c>>d; ana[b][a]=P(d,c); maps[b][a]= 'O' ; ana[d][c]=P(b,a); maps[d][c]= 'O' ; } /* for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ cout<<maps[i][j]; } cout<<endl; } */ if (dfs(sy,sx)){ cout<< "OK" <<endl; } else { cout<< "NO" <<endl; } } bool dfs( int y, int x){ //cout<<y<<" "<<x<<endl; if (mem[P(y,x)]!=0){ if (mem[P(y,x)]==1){ return true ; } else { return false ; } } else { for ( int i=0;i<4;i++){ int nx=x; int ny=y; while (maps[ny][nx]== '.' &&nx>=0&&nx<w&&ny>=0&&ny<h){ nx+=dx[i]; ny+=dy[i]; } //cout<<ny<<" "<<nx<<endl; if (nx>=0&&nx<w&&ny>=0&&ny<h){ if (maps[ny][nx]== 'G' ){ mem[P(y,x)]=1; return true ; } else if (maps[ny][nx]== 'O' ){ maps[ny][nx]= '.' ; maps[ana[ny][nx].F][ana[ny][nx].S]= '.' ; if (dfs(ana[ny][nx].F,ana[ny][nx].S)){ mem[P(y,x)]=1; return true ; } maps[ny][nx]= 'O' ; } else if (maps[ny][nx]== '@' ){ nx-=dx[i]; ny-=dy[i]; if (dfs(ny,nx)){ mem[P(y,x)]=1; return true ; } } } } mem[P(y,x)]=2; return false ; } } |
ステータス
項目 | データ |
---|---|
問題 | 0003 - 滑った故の結末 |
ユーザー名 | ei1417 |
投稿日時 | 2015-09-16 17:41:53 |
言語 | C++11 |
状態 | Runtime Error |
得点 | 0 |
ソースコード長 | 1854 Byte |
最大実行時間 | 157 ms |
最大メモリ使用量 | 12904 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 0 / 100 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
dfs-b_in1.txt | RE | 157 ms | 12764 KB |
1
|
dfs-b_in2.txt | RE | 28 ms | 12844 KB |
1
|
dfs-b_in3.txt | RE | 24 ms | 12784 KB |
1
|
dfs-b_in4.txt | AC | 24 ms | 568 KB |
1
|
dfs-b_in5.txt | AC | 16 ms | 628 KB |
1
|
dfs-b_in6.txt | AC | 19 ms | 424 KB |
1
|
dfs-b_in7.txt | RE | 33 ms | 12768 KB |
1
|
dfs-b_in8.txt | AC | 27 ms | 548 KB |
1
|
dfs-b_in9.txt | RE | 34 ms | 12892 KB |
1
|
dfs-b_in10.txt | RE | 28 ms | 12832 KB |
1
|
dfs-b_in11.txt | RE | 33 ms | 12904 KB |
1
|