Submission #1011842

#TimeUsernameProblemLanguageResultExecution timeMemory
1011842surenPatkice (COCI20_patkice)C++17
50 / 50
1 ms448 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...