Submission #13560


ソースコード

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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int
#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))
typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;
typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;
namespace std {
bool operator<(const P& a, const P& b) {
return a.X != b.X ? a.X < b.X : a.Y < b.Y;
}
}
int dist[110][110];
int H, W;
int sx, sy, gx, gy;
bool used[110][110];
char board[110][110];
bool src(int A, int B) {
queue<pii> q;
q.push(pii(A, B));
memset(used, false, sizeof(used));
rep(i,0,110) rep(j,0,110) dist[i][j] = INF;
dist[A][B] = 0;
used[A][B] = true;
while(!q.empty()) {
pii temp = q.front(); q.pop();
int x = temp.fr, y = temp.sc;
rep(i,0,4) {
int xx = x + dx[i], yy = y + dy[i];
if(xx < 0 || xx >= H || yy < 0 || yy >= W) continue;
if(board[xx][yy] == '#') continue;
if(used[xx][yy]) continue;
used[xx][yy] = true;
dist[xx][yy] = dist[x][y] + 1;
q.push(pii(xx,yy));
}
}
if(dist[gx][gy] != INF) return true;
else return false;
}
vector<pii> shortestpath() {
vector<pii> ret;
queue<pii> q;
q.push(pii(gx, gy));
int d = dist[gx][gy];
while(!q.empty()) {
pii temp = q.front(); q.pop();
ret.pb(temp);
int x = temp.fr, y = temp.sc;
rep(i,0,4) {
int xx = x + dx[i], yy = y + dy[i];
if(xx < 0 || xx >= H || yy < 0 || yy >= W) continue;
if(dist[xx][yy] != d - 1) continue;
q.push(pii(xx,yy));
d--;
}
}
return ret;
}
signed main() {
cin >> H >> W;
rep(i,0,H) rep(j,0,W) {
cin >> board[i][j];
if(board[i][j] == 'S') {
sx = i, sy = j;
}
else if(board[i][j] == 'G') {
gx = i, gy = j;
}
}
bool dm = src(sx, sy);
vector<pii> vs = shortestpath();
rep(i,0,vs.size()) {
if(vs[i] == pii(sx, sy) || vs[i] == pii(gx, gy)) continue;
int x = vs[i].fr, y = vs[i].sc;
board[x][y] = '#';
dm = src(sx, sy);
if(!dm) {
cout << "yes" << endl;
return 0;
}
board[x][y] = '.';
}
cout << "no" << endl;
return 0;
}

ステータス

項目 データ
問題 0650 - メロンパン
ユーザー名 tsutaj
投稿日時 2017-03-12 15:02:57
言語 C++11
状態 Accepted
得点 15
ソースコード長 3482 Byte
最大実行時間 45 ms
最大メモリ使用量 812 KB

セット

セット 得点 Cases
1 ALL 15 / 15 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
01_sample1.txt AC 37 ms 608 KB
1
01_sample2.txt AC 20 ms 608 KB
1
01_sample3.txt AC 18 ms 600 KB
1
02_random1.txt AC 22 ms 604 KB
1
02_random2.txt AC 25 ms 596 KB
1
02_random3.txt AC 19 ms 596 KB
1
02_random4.txt AC 20 ms 592 KB
1
02_random5.txt AC 22 ms 592 KB
1
02_random6.txt AC 22 ms 592 KB
1
02_random7.txt AC 12 ms 588 KB
1
02_random8.txt AC 23 ms 588 KB
1
02_random9.txt AC 21 ms 588 KB
1
02_random10.txt AC 26 ms 600 KB
1
03_random1.txt AC 26 ms 708 KB
1
03_random2.txt AC 17 ms 704 KB
1
03_random3.txt AC 22 ms 700 KB
1
03_random4.txt AC 17 ms 568 KB
1
03_random5.txt AC 19 ms 568 KB
1
03_random6.txt AC 15 ms 692 KB
1
04_ei1331.txt AC 23 ms 688 KB
1
04_ei1332.txt AC 19 ms 684 KB
1
04_ei1333.txt AC 19 ms 812 KB
1
04_ei1334.txt AC 45 ms 680 KB
1
04_ei1335.txt AC 19 ms 664 KB
1
05_random1.txt AC 26 ms 776 KB
1
05_random2.txt AC 17 ms 772 KB
1
05_random3.txt AC 17 ms 760 KB
1
05_random4.txt AC 17 ms 756 KB
1
05_random5.txt AC 19 ms 744 KB
1
05_random6.txt AC 18 ms 608 KB
1
06_handmake1.txt AC 21 ms 592 KB
1