Submission #484594

# Submission time Handle Problem Language Result Execution time Memory
484594 2021-11-04T14:45:09 Z groupATSU Patkice (COCI20_patkice) C++14
50 / 50
1 ms 716 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll inf=1e9;
const int maxn=1e3;
const ll mod=998244353;
int a,b;
char g[maxn][maxn];
int used[maxn][maxn];
void clr(){
	for(int i=1;i<=a;i++){
		for(int t=1;t<=b;t++)used[i][t]=0;
	}
}
vector <pair<int,char>> ans;
void DFS(int x,int y,int ind,int cnt){            
	if(g[x][y]=='.' || used[x][y]==1){
		return ;
	}
	if(g[x][y]=='x'){
		used[x][y]=1;
		if(ind==2)ans.push_back({cnt,'N'});
    	else if(ind==1)ans.push_back({cnt,'S'});
    	else if(ind==3)ans.push_back({cnt,'E'});
    	else ans.push_back({cnt,'W'});
    	return ;
    }
	used[x][y]=1;
	if(g[x][y]=='v')DFS(x+1,y,ind,cnt+1);
	if(g[x][y]=='^')DFS(x-1,y,ind,cnt+1);
	if(g[x][y]=='>')DFS(x,y+1,ind,cnt+1);
	if(g[x][y]=='<')DFS(x,y-1,ind,cnt+1);
}
void solve(){
	cin>>a>>b;
	pair <int,int> start,finish;
	for(int i=1;i<=a;i++){
		for(int t=1;t<=b;t++){
			cin>>g[i][t];
			if(g[i][t]=='o'){
				start.first=i;
				start.second=t; 			
			}
			if(g[i][t]=='x'){
				finish.first=i;
				finish.second=t;
			}
		}
	}
	DFS(start.first+1,start.second,1,1);
	clr();
	DFS(start.first-1,start.second,2,1);
	clr();
	DFS(start.first,start.second+1,3,1);
	clr();
	DFS(start.first,start.second-1,4,1);
	if(ans.size()!=0){
		sort(ans.begin(),ans.end());
		cout<<":)"<<endl;
		cout<<ans[0].second;
		return ;
	}else{
		cout<<":(";
	}
	
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        cout<<'\n';
    }


}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 456 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 0 ms 588 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 700 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 708 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 708 KB Output is correct
13 Correct 1 ms 716 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 324 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct