답안 #487840

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
487840 2021-11-16T19:10:36 Z inksamurai Patkice (COCI20_patkice) C++17
0 / 50
1 ms 332 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define crep(i,x,n) for(int i=x;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _3HaBFkZ ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
using pii=pair<int,int>;
using vi=vector<int>;

int main(){
_3HaBFkZ;
	int h,w;
	cin>>h>>w;
	vec(vec(char)) a(h,vec(char)(w));
	rep(i,h)rep(j,w) cin>>a[i][j];
	pii hm={-1,-1};
	rep(i,h)rep(j,w){
		if(a[i][j]=='o'){
			hm={i,j};
			break;
		}
	}
	const int di[]={1,-1,0,0};
	const int dj[]={0,0,1,-1};
	auto ok=[&](int x,int y)->bool{
		return !(min(x,y)<0 or x>=h or y>=w);
	};
	vec(vi) usd(h,vi(w));
	bool pok=0;
	auto dfs=[&](auto self,int x,int y){
		if(usd[x][y]) return;
		usd[x][y]=1;
		if(a[x][y]=='.' or a[x][y]=='o') return;
		if(a[x][y]=='x'){
			pok=1;
			return;
		}
		char ch=a[x][y];
		int dir=(ch=='v'?0:ch=='>'?2:ch=='<'?3:1);
		int nex=x+di[dir],ney=y+dj[dir];
		if(ok(nex,ney) and usd[nex][ney]==0){
			self(self,nex,ney);
		}
	};
	vec(string) pans;
	rep(dir,4){
		int nex=hm.fi+di[dir],ney=hm.se+dj[dir];
		if(ok(nex,ney)){
			usd=vec(vi)(h,vi(w,0));
			dfs(dfs,nex,ney);
			if(pok){
				if(dir==0){
					pans.pb("N");
				}
				if(dir==1){
					pans.pb("S");
				}
				if(dir==2){
					pans.pb("E");
				}
				if(dir==3){
					pans.pb("W");
				}
			}
		}
	}
	if(sz(pans)==0){
		cout<<":(\n";
	}else{
		sort(all(pans));
		cout<<":)\n";
		cout<<pans[0]<<"\n";
	}
//	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 320 KB Output isn't correct
3 Halted 0 ms 0 KB -