# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1011842 |
2024-07-01T09:37:40 Z |
suren |
Patkice (COCI20_patkice) |
C++17 |
|
1 ms |
448 KB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define S second
#define F first
string s[145];
ll n, m;
bool vis[145][145];
void clear(){
for(int i = 0; i < 100; i ++ ){
for(int j = 0; j < 100; j ++ )
vis[i][j] = 0;
}
}
pair< ll, ll > bfs( ll X, ll Y ){
queue< pair< pair< ll, ll >, ll > > q;
while( q.size() ){
q.pop();
}
q.push( { {X, Y}, 0 } );
while( q.size() ){
ll x = q.front().F.F;
ll y = q.front().F.S;
// cout << "coor" << x << " " << y <<"\n";
ll tier = q.front().S;
q.pop();
if( vis[x][y] == 1 )
continue;
vis[x][y] = 1;
if( s[x][y] == 'x' ){
return {1,tier};
}
// cout << "node:" << s[x][y] << "\n";
// cout << "vis" << vis[x][y] << "\n";
if( vis[x][y-1] == 0 && s[x][y] == '<' ){
q.push({{x,y-1}, tier+1});
continue;
}
if( vis[x-1][y] == 0 && s[x][y] == '^' ){
q.push({{x-1,y}, tier+1});
continue;
}
if( vis[x][y+1] == 0 && s[x][y] == '>' ){
q.push({{x,y+1}, tier+1});
continue;
}
if( vis[x+1][y] == 0 && s[x][y] == 'v' ){
q.push({{x+1,y}, tier+1});
continue;
}
return {0,0};
}
return {0,0};
}
int main(){
// ios_base::sync_with_stdio(NULL);
// cin.tie(NULL);
// cout.tie(NULL);
cin >> n >> m;
for(int i = 0; i < n; i ++ )
cin >> s[i];
ll stx, sty;
for(int i = 0; i < n; i ++ ){
for(int j = 0; j < m; j ++ ){
if( s[i][j] == 'o' ){
stx = i, sty = j;
}
}
}
vector < pair< ll, char > > ans;
pair < ll, ll > p;
clear();
if( sty > 0 ){
p = bfs( stx, sty-1 );
if( p.F == 1 ){
ans.pb( {p.S, 'W'} );
}
}
clear();
if( sty < m-1 ){
p = bfs( stx, sty+1 );
if( p.F == 1 ){
ans.pb( {p.S, 'E'} );
}
}
clear();
if( stx > 0 ){
p = bfs( stx-1, sty );
if( p.F == 1 ){
ans.pb( {p.S, 'N'} );
}
}
clear();
if( stx < n-1 ){
p = bfs( stx+1, sty );
if( p.F == 1 ){
ans.pb( {p.S, 'S'} );
}
}
sort( ans.begin(), ans.end() );
if( ans.size() > 0 ){
cout << ":)\n";
cout << ans[0].S << "\n";
}else{
cout << ":(\n";
}
return 0;
}
Compilation message
patkice.cpp: In function 'int main()':
patkice.cpp:85:23: warning: 'sty' may be used uninitialized in this function [-Wmaybe-uninitialized]
85 | p = bfs( stx, sty+1 );
| ^
patkice.cpp:99:23: warning: 'stx' may be used uninitialized in this function [-Wmaybe-uninitialized]
99 | p = bfs( stx+1, sty );
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
448 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |