Submission #232070


Source Code Expand

#include <cstdio>
#include <cstring>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int dx[]={1,1,0,-1,-1,-1,0,1};
const int dy[]={0,-1,-1,-1,0,1,1,1};

int main(){
	int h,w; scanf("%d%d",&h,&w);
	char B[52][53];
	rep(i,h) scanf("%s",B[i+1]+1);
	rep(j,w+2) B[0][j]=B[h+1][j]='#';
	rep(i,h+2) B[i][0]=B[i][w+1]='#';
	h+=2;
	w+=2;

	int i0,j0;
	rep(i,h) rep(j,w) if(strchr("^v<>",B[i][j])) i0=i, j0=j;
	int dir0;
	if     (B[i0][j0]=='^') dir0=2;
	else if(B[i0][j0]=='v') dir0=6;
	else if(B[i0][j0]=='<') dir0=4;
	else                    dir0=0;
	B[i0][j0]='.';
	int hand0=(dir0+6)%8;

	bool vis[52][52]={};
	int i=i0,j=j0,dir=dir0,hand=hand0;
	rep(_,1000000){
		vis[i][j]=true;

		if(B[i][j]=='G'){
			int ans=0;
			rep(y,h) rep(x,w) if(vis[y][x]) ans++;
			printf("%d\n",ans);
			return 0;
		}

		if(B[i+dy[(dir+6)%8]][j+dx[(dir+6)%8]]!='#'){
			dir=(dir+6)%8;
			i+=dy[dir];
			j+=dx[dir];
			continue;
		}

		if(B[i+dy[dir]][j+dx[dir]]!='#'){
			i+=dy[dir];
			j+=dx[dir];
			continue;
		}

		dir=(dir+2)%8;
	}

	puts("-1");

	return 0;
}

Submission Info

Submission Time
Task B - 不審者
User fura2
Language C++ (GCC 4.4.7)
Score 100
Code Size 1124 Byte
Status AC
Exec Time 38 ms
Memory 928 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:12: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
./Main.cpp:14: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 60
Set Name Test Cases
All 05_test_00, 05_test_01, 05_test_02, 05_test_03, 10_dir_00, 10_dir_01, 10_dir_02, 10_dir_03, 10_dir_10, 10_dir_11, 10_dir_12, 10_dir_13, 10_dir_20, 10_dir_21, 10_dir_22, 10_dir_23, 15_test_01, 15_test_02, 15_test_03, 15_test_04, 15_test_05, 15_test_06, 15_test_07, 15_test_08, 15_test_09, 15_test_10, 20_Wall10_00, 20_Wall10_01, 20_Wall10_02, 20_Wall10_03, 20_Wall10_04, 20_Wall20_00, 20_Wall20_01, 20_Wall20_02, 20_Wall20_03, 20_Wall20_04, 20_Wall30_00, 20_Wall30_01, 20_Wall30_02, 20_Wall30_03, 20_Wall30_04, 20_Wall40_00, 20_Wall40_01, 20_Wall40_02, 20_Wall40_03, 20_Wall40_04, 25_Continent_00, 25_Continent_01, 25_Continent_02, 25_Continent_03, 25_Continent_04, 27_Continent_00, 27_Continent_01, 27_Continent_02, 27_Continent_03, 27_Continent_04, 30_Maximum_00, 30_Maximum_01, 35_Maximum_00, 35_Maximum_01
Case Name Status Exec Time Memory
05_test_00 AC 23 ms 928 KB
05_test_01 AC 22 ms 796 KB
05_test_02 AC 36 ms 672 KB
05_test_03 AC 23 ms 800 KB
10_dir_00 AC 24 ms 792 KB
10_dir_01 AC 26 ms 800 KB
10_dir_02 AC 25 ms 924 KB
10_dir_03 AC 23 ms 672 KB
10_dir_10 AC 23 ms 800 KB
10_dir_11 AC 24 ms 676 KB
10_dir_12 AC 24 ms 840 KB
10_dir_13 AC 24 ms 800 KB
10_dir_20 AC 24 ms 800 KB
10_dir_21 AC 22 ms 920 KB
10_dir_22 AC 24 ms 800 KB
10_dir_23 AC 22 ms 928 KB
15_test_01 AC 34 ms 800 KB
15_test_02 AC 22 ms 668 KB
15_test_03 AC 22 ms 800 KB
15_test_04 AC 23 ms 800 KB
15_test_05 AC 24 ms 796 KB
15_test_06 AC 23 ms 800 KB
15_test_07 AC 22 ms 796 KB
15_test_08 AC 23 ms 676 KB
15_test_09 AC 36 ms 668 KB
15_test_10 AC 23 ms 800 KB
20_Wall10_00 AC 34 ms 668 KB
20_Wall10_01 AC 25 ms 792 KB
20_Wall10_02 AC 38 ms 732 KB
20_Wall10_03 AC 25 ms 792 KB
20_Wall10_04 AC 25 ms 664 KB
20_Wall20_00 AC 36 ms 792 KB
20_Wall20_01 AC 25 ms 792 KB
20_Wall20_02 AC 37 ms 792 KB
20_Wall20_03 AC 25 ms 924 KB
20_Wall20_04 AC 36 ms 796 KB
20_Wall30_00 AC 36 ms 796 KB
20_Wall30_01 AC 25 ms 732 KB
20_Wall30_02 AC 25 ms 796 KB
20_Wall30_03 AC 32 ms 796 KB
20_Wall30_04 AC 26 ms 672 KB
20_Wall40_00 AC 33 ms 800 KB
20_Wall40_01 AC 38 ms 800 KB
20_Wall40_02 AC 35 ms 800 KB
20_Wall40_03 AC 36 ms 796 KB
20_Wall40_04 AC 37 ms 800 KB
25_Continent_00 AC 23 ms 800 KB
25_Continent_01 AC 36 ms 800 KB
25_Continent_02 AC 24 ms 920 KB
25_Continent_03 AC 24 ms 800 KB
25_Continent_04 AC 33 ms 808 KB
27_Continent_00 AC 23 ms 800 KB
27_Continent_01 AC 23 ms 800 KB
27_Continent_02 AC 23 ms 924 KB
27_Continent_03 AC 24 ms 800 KB
27_Continent_04 AC 22 ms 924 KB
30_Maximum_00 AC 23 ms 796 KB
30_Maximum_01 AC 24 ms 700 KB
35_Maximum_00 AC 22 ms 800 KB
35_Maximum_01 AC 24 ms 800 KB