-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16866.cpp
More file actions
59 lines (51 loc) · 1.24 KB
/
16866.cpp
File metadata and controls
59 lines (51 loc) · 1.24 KB
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
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
using namespace std;
const ll INF = 1e9 + 7;
const ll DIV = 987654321;
int n, m;
int r, c;
int arr[255][255];
int main()
{
fastio;
cin >> m >> n;
for(int i =0 ;i < m;i++){
for(int j = 0 ;j < n;j++){
cin >> arr[i][j];
}
}
cin >> r>>c;
r--;
c--;
vector<int> ans;
ans.push_back(arr[r][c]);
bool f = 0;
while(1){
if(r < 0 || c < 0 || r >= m || c >=n) break;
if(ans.size() > n * m) break;
if(arr[r][c] == -1){
f = 1;
break;
}
ans.push_back(arr[r][c]);
bool t = 0;
for(int i =0 ;i < 4;i++){
int nr = r + "1012"[i] -'1', nc = c + "2101"[i] - '1';
if(nr < 0 || nc < 0 || nr >= m || nc >=n || arr[nr][nc] == -2 || arr[r][c] != arr[nr][nc]) continue;
r = nr + "1012"[i] -'1';
c = nc + "2101"[i] - '1';
t = 1;
break;
}
if(t == 0) break;
}
if(f){
reverse(ans.begin(), ans.end());
ans.pop_back();
for(int i : ans) cout << i << " ";
}
else cout <<"impossible";
return 0;
}