Submission #804984

# Submission time Handle Problem Language Result Execution time Memory
804984 2023-08-03T12:17:20 Z Tunglam07 Patkice (COCI20_patkice) C++17
50 / 50
1 ms 340 KB
#include <bits/stdc++.h>
using namespace std;

long long dx[]={0,-1,1,0};
long long dy[]={1,0,0,-1};
char a[101][101];

long long dfs(long long x,long long y)
{
    if (a[x][y]=='x') 
	{
		return 1;
	}
    if (a[x][y]=='.' || a[x][y]=='o') 
	{
		return INT_MIN;
	}
    if (a[x][y]=='^') 
	{
		return dfs(x-1,y)+1;
	}
    if (a[x][y]=='v') 
	{
		return dfs(x+1,y)+1;
	}
    if (a[x][y]=='>') 
	{
		return dfs(x,y+1)+1;
	}
    if (a[x][y]=='<') 
	{
		return dfs(x,y-1)+1;
	}
}

int main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	long long n,m, x=0, y=0;
    char c = 'h';
    cin >> n >> m;
    for (int i=1;i<=n;i++)
	{
        for (int j=1;j<=m;j++)
		{
            cin>>a[i][j];
            if (a[i][j]=='o')
			{
                x=i;
                y=j;
            }
        }
    }
    long long maxi=INT_MAX;
    bool ck=0;
    for (int i=0;i<4;i++)
	{
        long long d = dfs(x+dx[i],y+dy[i]);
        if (d<0) 
		{
			continue;
		}
        ck=true;
        if (d<maxi)
		{
            maxi=d;
            if (i==0) 
			{
				c='E';
			}
            else if (i==1) 
			{
				c='N';
			}
            else if (i==2) 
			{
				c='S';
			}
            else if (i==3) 
			{
				c='W';
			}
        }
    }
    if (ck) 
	{
		cout << ":)" << endl << c << endl;
	}
    else 
	{
		cout<<":("<<endl;
	}
}

Compilation message

patkice.cpp: In function 'long long int dfs(long long int, long long int)':
patkice.cpp:34:1: warning: control reaches end of non-void function [-Wreturn-type]
   34 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 328 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct