Submission #1347145

#TimeUsernameProblemLanguageResultExecution timeMemory
1347145jumpPatkice (COCI20_patkice)C++20
50 / 50
0 ms348 KiB
#include <bits/stdc++.h>
#define int long long
//definitely not done by chatgpt because my code segfaulted
int r,s;
char a[110][110];

int dx[256], dy[256];

signed main(){
	std::cin>>r>>s;
	
	for(int i=1;i<=r;i++){
		for(int j=1;j<=s;j++){
			std::cin>>a[i][j];
		}
	}
	
	int sx,sy;
	for(int i=1;i<=r;i++){
		for(int j=1;j<=s;j++){
			if(a[i][j]=='o'){
				sx=i; sy=j;
			}
		}
	}
	
	// directions
	std::vector<char> dir = {'E','N','S','W'};
	dx['N']=-1; dy['N']=0;
	dx['S']=1; dy['S']=0;
	dx['E']=0; dy['E']=1;
	dx['W']=0; dy['W']=-1;
	
	// currents
	dx['^']=-1; dy['^']=0;
	dx['v']=1; dy['v']=0;
	dx['>']=0; dy['>']=1;
	dx['<']=0; dy['<']=-1;
	
	int best = 1e18;
	char ans = '?';
	
	for(char d:dir){
		int x = sx + dx[d];
		int y = sy + dy[d];
		int step = 1;
		
		while(true){
			if(a[x][y]=='.' || a[x][y]=='o') break;
			if(a[x][y]=='x'){
				if(step < best || (step==best && d<ans)){
					best = step;
					ans = d;
				}
				break;
			}
			
			char c = a[x][y];
			x += dx[c];
			y += dy[c];
			step++;
		}
	}
	
	if(best==1e18){
		std::cout<<":(\n";
	}else{
		std::cout<<":)\n";
		std::cout<<ans<<"\n";
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...