Submission #00044


ソースコード

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
#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';
}
if(dfs(sy,sx)){
cout<<"OK"<<endl;
}
else{
cout<<"NO"<<endl;
}
}
bool dfs(int y,int x){
maps[y][x]='N';
for(int i=0;i<4;i++){
int nx=x+dx[i];
int ny=y+dy[i];
while(maps[ny][nx]=='.'&&nx>=0&&nx<w&&ny>=0&&ny<h){
nx+=dx[i];
ny+=dy[i];
}
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';
maps[ana[ny][nx].F][ana[ny][nx].S]='O';
}
else if(maps[ny][nx]=='@'){
nx-=dx[i];
ny-=dy[i];
if(maps[ny][nx]=='N'){
return false;
}
maps[ny][nx]='N';
if(dfs(ny,nx)){
mem[P(y,x)]=1;
return true;
}
}
else if(maps[ny][nx]=='N'){
return false;
}
}
}
mem[P(y,x)]=2;
maps[y][x]='.';
return false;
}

ステータス

項目 データ
問題 0003 - 滑った故の結末
ユーザー名 ei1417
投稿日時 2015-09-16 17:54:37
言語 C++11
状態 Wrong Answer
得点 0
ソースコード長 1768 Byte
最大実行時間 25 ms
最大メモリ使用量 720 KB

セット

セット 得点 Cases
1 ALL 0 / 100 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
dfs-b_in1.txt AC 18 ms 476 KB
1
dfs-b_in2.txt WA 25 ms 520 KB
1
dfs-b_in3.txt WA 16 ms 448 KB
1
dfs-b_in4.txt AC 21 ms 504 KB
1
dfs-b_in5.txt AC 22 ms 556 KB
1
dfs-b_in6.txt AC 18 ms 612 KB
1
dfs-b_in7.txt WA 20 ms 664 KB
1
dfs-b_in8.txt AC 19 ms 584 KB
1
dfs-b_in9.txt WA 13 ms 640 KB
1
dfs-b_in10.txt WA 20 ms 664 KB
1
dfs-b_in11.txt AC 19 ms 720 KB
1