Submission #320864

#TimeUsernameProblemLanguageResultExecution timeMemory
320864colazcyPatkice (COCI20_patkice)C++17
50 / 50
1 ms1132 KiB
#include <cstdio> #include <cstring> #include <vector> #include <queue> using namespace std; typedef long long ll; const int maxn = 128,dx[] = {0,-1,1,0},dy[] = {1,0,0,-1}; const char *str = "ENSW"; struct edge{int v,d;}; vector<edge> G[maxn * maxn]; inline void addedge(int u,int v,int d){G[u].push_back(edge{v,d});} int n,m,vis[maxn * maxn]; inline int get(int x,int y){return (x - 1) * m + y;} struct node{ int u; ll h; bool operator < (const node &rhs)const{ return h > rhs.h; } }; ll dis[maxn * maxn]; inline void dijkstra(int s){ memset(dis,0x7f,sizeof(dis)); memset(vis,0,sizeof(vis)); dis[s] = 0; priority_queue<node> q; q.push(node{s,0}); while(!q.empty()){ int u = q.top().u;q.pop(); if(vis[u])continue; vis[u] = 1; for(int i = 0;i < (int)G[u].size();i++){ const edge &e = G[u][i]; if(dis[u] + e.d < dis[e.v]){ dis[e.v] = dis[u] + e.d; q.push(node{e.v,dis[e.v]}); } } } } char mp[maxn][maxn]; int main(){ scanf("%d %d",&n,&m); for(int i = 1;i <= n;i++)scanf("%s",mp[i] + 1); for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++) if(mp[i][j] == '<')addedge(get(i,j),get(i,j - 1),1); else if(mp[i][j] == '>')addedge(get(i,j),get(i,j + 1),1); else if(mp[i][j] == '^')addedge(get(i,j),get(i - 1,j),1); else if(mp[i][j] == 'v')addedge(get(i,j),get(i + 1,j),1); int sx,sy,tx,ty; for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++) if(mp[i][j] == 'o')sx = i,sy = j; else if(mp[i][j] == 'x')tx = i,ty = j; ll tmp = 0x7fffffffffffffff;char ans = 'G'; for(int i = 0;i < 4;i++){ int nx = sx + dx[i],ny = sy + dy[i]; dijkstra(get(nx,ny)); if(dis[get(tx,ty)] < tmp){ tmp = dis[get(tx,ty)]; ans = str[i]; } } if(tmp != 0x7f7f7f7f7f7f7f7f)puts(":)"),putchar(ans); else puts(":("); return 0; }

Compilation message (stderr)

patkice.cpp: In function 'int main()':
patkice.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   43 |  scanf("%d %d",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~~
patkice.cpp:44:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |  for(int i = 1;i <= n;i++)scanf("%s",mp[i] + 1);
      |                           ~~~~~^~~~~~~~~~~~~~~~
patkice.cpp:13:50: warning: 'ty' may be used uninitialized in this function [-Wmaybe-uninitialized]
   13 | inline int get(int x,int y){return (x - 1) * m + y;}
      |                                                  ^
patkice.cpp:51:15: note: 'ty' was declared here
   51 |  int sx,sy,tx,ty;
      |               ^~
patkice.cpp:51:12: warning: 'tx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   51 |  int sx,sy,tx,ty;
      |            ^~
patkice.cpp:58:23: warning: 'sy' may be used uninitialized in this function [-Wmaybe-uninitialized]
   58 |   int nx = sx + dx[i],ny = sy + dy[i];
      |                       ^~
patkice.cpp:58:7: warning: 'sx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   58 |   int nx = sx + dx[i],ny = sy + dy[i];
      |       ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...