# include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
using namespace std;
const int N = 105;
int n,ans1,ans,m,vert,lsti,lstj,sti,stj;
char ch[N][N], chh[N*N],ans2,ch1;
map <char, int> a,b;
int fix[N*N];
vector <int > v[N*N];
int get(int i, int j) {
return (i - 1) * m + j;
}
void go(int cur, int sz) {
// cout<<cur<<" "<<sz<<endl;
if (ans1) return ;
if (chh[cur] == 'o' || chh[cur] == '.' || fix[cur]) {
ans1 = 1e9; return ;
}
if (chh[cur] == 'x') {
ans1 = sz;
return ;
}
fix[cur] = 1;
for(int j = 0; j < v[cur].size(); j++) {
vert = v[cur][j];
go(vert, sz + 1);
}
}
void init() {
for (int i = 1; i <= n*m; i++) {
fix[i] = 0;
}
ans1 = 0;
}
main() {
//E N S W
cin>>n>>m;
a['>'] = 0; a['<'] = 0; a['v'] = 1; a['^'] = -1;
b['>'] = 1; b['<'] = -1; b['v'] = 0; b['^'] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin>>ch[i][j];
chh[get(i,j)] = ch[i][j];
ch1 = ch[i][j];
// if (i == 11 && j == 8) cout<<ch1<<" "<<i + a[ch1]<<" "<<j+b[ch1]<<endl;
if (ch1 == 'o') {
sti = i;
stj = j;
continue;
}
if (ch1 == 'x') {
lsti = i;
lstj = j;
continue;
}
if (ch1 == '.') continue;
v[get(i,j)].pb(get(i + a[ch1], j + b[ch1]));
}
}
ans = 2e9;
ans1 = 0;
go(get(sti, stj + 1),1);
if (ans > ans1) ans = ans1, ans2 = 'E';
init();
ans1 = 0;
go(get(sti - 1, stj),1);
if (ans > ans1) ans = ans1, ans2 = 'N';
init();
go(get(sti +1, stj),1);
if (ans > ans1) ans = ans1, ans2 = 'S';
init();
// cout<<sti<<" "<<stj<<endl;
// cout<<get(sti,stj - 1)<<endl;
go(get(sti, stj - 1),1);
if (ans > ans1) ans = ans1, ans2 = 'W';
if (ans >= 1e9) cout<<":(";
else cout<<":)\n"<<ans2<<endl;
}
Compilation message
patkice.cpp: In function 'void go(int, int)':
patkice.cpp:26:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int j = 0; j < v[cur].size(); j++) {
| ~~^~~~~~~~~~~~~~~
patkice.cpp: At global scope:
patkice.cpp:37:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
37 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
556 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
568 KB |
Output is correct |
6 |
Correct |
1 ms |
588 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
588 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
588 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
1 ms |
588 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
588 KB |
Output is correct |
9 |
Correct |
1 ms |
560 KB |
Output is correct |
10 |
Correct |
2 ms |
716 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
716 KB |
Output is correct |
13 |
Correct |
1 ms |
588 KB |
Output is correct |
14 |
Correct |
1 ms |
560 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |