Submission #480914

#TimeUsernameProblemLanguageResultExecution timeMemory
480914CSQ31Patkice (COCI20_patkice)C++17
0 / 50
1 ms332 KiB
#pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define sz(a) (int)(a.size()) #define all(a) a.begin(),a.end() #define lb lower_bound #define ub upper_bound #define owo ios_base::sync_with_stdio(0);cin.tie(0); #define MOD (ll)(998244353) #define INF (ll)(1e18) #define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr) #define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\ debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC)) typedef long long int ll; typedef long double ld; typedef pair<ll,ll> PII; typedef pair<int,int> pii; typedef vector<vector<int>> vii; typedef vector<vector<ll>> VII; ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);} char g[200][200]; int dist[200][200]; char c[4] = {'E','N','S','W'}; int dy[4] = {1,0,0,-1}; int dx[4] = {0,-1,1,0}; int r,s; bool check(int x,int y){ return x>=0 && x<r && y>=0 && y<s; } int main() { cin>>r>>s; int sx,sy,tx,ty; sx = sy = tx = ty = 0; for(int i=0;i<r;i++){ for(int j=0;j<s;j++){ cin>>g[i][j]; if(g[i][j] == 'o'){ sx = i; sy = j; } if(g[i][j] == 'x'){ tx = i; ty = j; } } } int ans = 1e9; char f = 'Z'; for(int i=0;i<4;i++){ int x = sx+dx[i]; int y = sy+dy[i]; if(!check(x,y))continue; dist[x][y] = 1; dist[tx][ty] = 1e9+1; while(true){ int d = dist[x][y]; if(g[x][y] == 'o' || g[x][y] == '.' || g[x][y] == 'x')break; if(g[x][y] == '^')x--; else if(g[x][y] == 'v')x++; else if(g[x][y] == '>')y++; else y--; dist[x][y] = d+1; } if(dist[tx][ty] != 1e9+1){ cout<<":)"<<'\n'; cout<<c[i]<<'\n'; return 0; } if(dist[tx][ty] < ans){ ans = dist[tx][ty]; f = c[i]; } else if(dist[tx][ty] == ans)f = min(c[i],f); } if(ans == 1e9)cout<<":("<<'\n'; else{ cout<<":)"<<'\n'; cout<<f<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...