Submission #967475

#TimeUsernameProblemLanguageResultExecution timeMemory
967475MilosMilutinovicPatkice (COCI20_patkice)C++14
50 / 50
1 ms696 KiB
#include<bits/stdc++.h> #define pb push_back #define fi first #define se second #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef long double ld; template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;} template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;} ll readint(){ ll x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } const int dx[]={1,0,-1,0}; const int dy[]={0,1,0,-1}; const string str="SENW"; int n,m; char s[105][105]; bool was[105][105]; bool valid(int x,int y){ return 1<=x&&x<=n&&1<=y&&y<=m; } int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%s",s[i]+1); int sx,sy,fx,fy; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(s[i][j]=='o'){ sx=i; sy=j; } if(s[i][j]=='x'){ fx=i; fy=j; } } } char res='a'; int mn=10000; for(int dir=0;dir<4;dir++){ if(!valid(sx+dx[dir],sy+dy[dir])){ continue; } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ was[i][j]=false; } } int cnt=1,cx=sx+dx[dir],cy=sy+dy[dir]; was[cx][cy]=true; while(cx!=fx||cy!=fy){ int nx=cx,ny=cy; if(s[cx][cy]=='^') nx=cx-1,ny=cy; if(s[cx][cy]=='v') nx=cx+1,ny=cy; if(s[cx][cy]=='<') nx=cx,ny=cy-1; if(s[cx][cy]=='>') nx=cx,ny=cy+1; if(!valid(nx,ny)||was[nx][ny]) break; cnt++; cx=nx; cy=ny; was[cx][cy]=true; } if(cx==fx&&cy==fy){ if(cnt<mn){ mn=cnt; res=str[dir]; }else if(cnt==mn){ chkmin(res,str[dir]); } } } if(res=='a') printf(":("); else printf(":)\n%c",res); return 0; }

Compilation message (stderr)

patkice.cpp: In function 'int main()':
patkice.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  scanf("%d%d",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~
patkice.cpp:39:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |  for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
      |                        ~~~~~^~~~~~~~~~~~~
patkice.cpp:66:19: warning: 'fy' may be used uninitialized in this function [-Wmaybe-uninitialized]
   66 |   while(cx!=fx||cy!=fy){
      |                 ~~^~~~
patkice.cpp:66:11: warning: 'fx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   66 |   while(cx!=fx||cy!=fy){
      |         ~~^~~~
patkice.cpp:56:12: warning: 'sy' may be used uninitialized in this function [-Wmaybe-uninitialized]
   56 |   if(!valid(sx+dx[dir],sy+dy[dir])){
      |       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
patkice.cpp:56:12: warning: 'sx' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...