답안 #1016116

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1016116 2024-07-07T12:05:04 Z vjudge1 Patkice (COCI20_patkice) C++17
50 / 50
1 ms 440 KB
#include <bits/stdc++.h>

using namespace std;

const int M = 101;

char a[M][M];

pair<char,int> calc(int x,int y)
{
	pair<char,int> ans;
	if (a[x][y]=='^')
		ans=calc(x-1,y);
	else if (a[x][y]=='>')
		ans=calc(x,y+1);
	else if (a[x][y]=='<')
		ans=calc(x,y-1);
	else if(a[x][y]=='v')
		ans=calc(x+1,y);
	else
		return {a[x][y],0};
	ans.second++;
	return ans;
}

int main()
{
	int n,m;
	cin>>n>>m;
	int sti,stj;
	for (int i=0;i<n;i++)
		for (int j=0;j<m;j++)
		{
			cin>>a[i][j];
			if (a[i][j]=='o')
				sti=i,stj=j;
		}
	int px[4]={0,-1,1,0},py[4]={1,0,0,-1};
	string dir="ENSW";
	int mn=M*M;
	char ans;
	for (int d=0;d<4;d++)
	{
		int ci=sti+px[d],cj=stj+py[d];
		auto x=calc(ci,cj);
		if (x.first=='x')
		{
			if (mn>x.second)
				mn=x.second,ans=dir[d];
		}
	}
	if (mn<M*M)
	{
		cout<<":)"<<endl;
		cout<<ans<<endl;
	}
	else
		cout<<":("<<endl;
	
	return 0;
}

Compilation message

patkice.cpp: In function 'int main()':
patkice.cpp:44:20: warning: 'stj' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |   int ci=sti+px[d],cj=stj+py[d];
      |                    ^~
patkice.cpp:44:7: warning: 'sti' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |   int ci=sti+px[d],cj=stj+py[d];
      |       ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 440 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct