Submission #493473

# Submission time Handle Problem Language Result Execution time Memory
493473 2021-12-11T14:37:51 Z uncripted Awesome Arrowland Adventure (eJOI19_adventure) C++11
0 / 100
2000 ms 204 KB
#include<bits/stdc++.h>
using namespace std;
char r[200];

int dif(char a, char b){
	int s=0;
	if(a=='X'){
		return 100000;
	}
	//	cout<<a<<" "<<b<<endl;
		
	while(a!=b){
	
		a=r[a];
		s++;
	}
//	cout<<"end"<<endl;
	 return s;
}
int main(){
r['N']='E';
r['E']='S';
r['S']='W';
r['W']='N';

int m,n;
cin>>m>>n;

char a[m][n];
int dp[m][n];
dp[0][0]=0;
for(int i=0; i<m; i++){
	for(int j=0; j<n; j++){
		cin>>a[i][j];
	}
}

dp[1][0]=dif(a[0][0], 'S');
//cout<<"dp1 "<<dp[1][0];
for(int i=1; i<n; i++){
	for(int j=0; j<m; j++){
		int x=dif(a[j][i-1], 'E');
		int y=dif(a[1-j][i], 'N');
		int y1=dif(a[1-j][i], 'S');
		int z=dif(a[1-j][i-1], 'E');
		if(j==0){
			dp[j][i]=min(dp[j][i-1]+x, dp[1-j][i-1]+y+z);
		}else{
			dp[j][i]=min(dp[j][i-1]+x, dp[1-j][i-1]+y1+z);	
		}
	}
}
cout<<dp[m-1][n-1];


}
/*
2 5
E E N W S
E E E E X
*/

Compilation message

adventure.cpp: In function 'int dif(char, char)':
adventure.cpp:14:7: warning: array subscript has type 'char' [-Wchar-subscripts]
   14 |   a=r[a];
      |       ^
# Verdict Execution time Memory Grader output
1 Execution timed out 2088 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2088 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2081 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2088 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -