Japan Alumni Group Summer Camp 2014 Day 4

Submission #232559

Source codeソースコード

#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>

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

using namespace std;

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

int h,w;
char B[50][51];

int idx,ans;
char s[1001];

int x,y,dir;
bool vis[50][50][4][1001][2][2]; // [y][x][dir][idx][skip][program/sentence]

#define CHECK(i) { if(vis[y][x][dir][idx][skip?1:0][i]){ puts("-1"); exit(0); } vis[y][x][dir][idx][skip?1:0][i]=true; }

void program(bool);

bool condition(){
	bool neg=false;
	if(s[idx]=='~') neg=true, idx++;
	switch(s[idx]){
		case 'N': idx++; return neg^(dir==1);
		case 'E': idx++; return neg^(dir==0);
		case 'S': idx++; return neg^(dir==3);
		case 'W': idx++; return neg^(dir==2);
		case 'C': idx++; return neg^(B[y+dy[dir]][x+dx[dir]]=='#');
		case 'T': idx++; return !neg;
		default: assert(0);
	}
}

void sentence(bool skip){
	// if
	if(s[idx]=='['){
		idx++;
		CHECK(1);
		if(condition()){
			CHECK(1);
			program(skip);
		}
		else{
			CHECK(1);
			program(true);
		}
		assert(s[idx]==']');
		idx++;
	}
	// while
	else if(s[idx]=='{'){
		idx++;
		int idx0=idx;
		CHECK(1);
		while(condition()){
			CHECK(1);
			program(skip);
			idx=idx0;
		}
		program(true);
		assert(s[idx]=='}');
		idx++;
	}
	// move
	else{
		if(!skip) ans++;
		int dir2=(dir+2)%4;
		switch(s[idx]){
			case '^': if(!skip && B[y+dy[dir ]][x+dx[dir ]]!='#') y+=dy[dir ], x+=dx[dir ]; break;
			case 'v': if(!skip && B[y+dy[dir2]][x+dx[dir2]]!='#') y+=dy[dir2], x+=dx[dir2]; break;
			case '<': if(!skip) dir=(dir+1)%4; break;
			case '>': if(!skip) dir=(dir+3)%4; break;
			default: assert(0);
		}
		if(B[y][x]=='g'){ printf("%d\n",ans); exit(0); }
		idx++;
	}
}

void program(bool skip){
	while(s[idx] && strchr("[{^v<>",s[idx])){
		CHECK(0);
		sentence(skip);
	}
}

int main(){
	scanf("%d%d",&h,&w);
	rep(i,h) scanf("%s",B[i]);
	scanf("%s",s);

	rep(i,h) rep(j,w) if(B[i][j]=='s') y=i, x=j, B[i][j]='.';
	dir=1;

	idx=ans=0;
	program(false);
	puts("-1");

	return 0;
}

Submission

Task問題 E - AI
User nameユーザ名 fura
Created time投稿日時
Language言語 C++ (GCC 4.4.7)
Status状態 WA
Score得点 0
Source lengthソースコード長 2085 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Compiler messageコンパイルメッセージ

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

Test case

Set

Set name Score得点 / Max score Cases
All 0 / 100 00-sample1,00-sample2,00-sample3,01-corner-empty,01-corner-infinite-loop1,01-corner-infinite-loop2,01-corner-infinite-loop3,01-corner-infinite-loop4,02-large1,02-large2,02-large3,02-large4,02-large5,02-large6,03-misc1,03-misc2,04-maze-move-only-failure1,04-maze-move-only-failure10,04-maze-move-only-failure2,04-maze-move-only-failure3,04-maze-move-only-failure4,04-maze-move-only-failure5,04-maze-move-only-failure6,04-maze-move-only-failure7,04-maze-move-only-failure8,04-maze-move-only-failure9,04-maze-move-only-success1,04-maze-move-only-success10,04-maze-move-only-success2,04-maze-move-only-success3,04-maze-move-only-success4,04-maze-move-only-success5,04-maze-move-only-success6,04-maze-move-only-success7,04-maze-move-only-success8,04-maze-move-only-success9,04-maze-random-failure1,04-maze-random-failure10,04-maze-random-failure2,04-maze-random-failure3,04-maze-random-failure4,04-maze-random-failure5,04-maze-random-failure6,04-maze-random-failure7,04-maze-random-failure8,04-maze-random-failure9,04-maze-random-success1,04-maze-random-success10,04-maze-random-success2,04-maze-random-success3,04-maze-random-success4,04-maze-random-success5,04-maze-random-success6,04-maze-random-success7,04-maze-random-success8,04-maze-random-success9,04-maze-simple-failure1,04-maze-simple-failure10,04-maze-simple-failure2,04-maze-simple-failure3,04-maze-simple-failure4,04-maze-simple-failure5,04-maze-simple-failure6,04-maze-simple-failure7,04-maze-simple-failure8,04-maze-simple-failure9,04-maze-simple-success1,04-maze-simple-success10,04-maze-simple-success2,04-maze-simple-success3,04-maze-simple-success4,04-maze-simple-success5,04-maze-simple-success6,04-maze-simple-success7,04-maze-simple-success8,04-maze-simple-success9,05-nest1,05-nest2,06-long1

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00-sample1 AC 33 ms 1296 KB
00-sample2 AC 37 ms 1308 KB
00-sample3 AC 35 ms 1292 KB
01-corner-empty AC 34 ms 1296 KB
01-corner-infinite-loop1 AC 34 ms 1300 KB
01-corner-infinite-loop2 AC 35 ms 1304 KB
01-corner-infinite-loop3 AC 34 ms 1296 KB
01-corner-infinite-loop4 AC 34 ms 1300 KB
02-large1 AC 66 ms 10768 KB
02-large2 WA
02-large3 AC 35 ms 1936 KB
02-large4 AC 35 ms 1940 KB
02-large5 WA
02-large6 WA
03-misc1 AC 32 ms 1424 KB
03-misc2 AC 32 ms 1296 KB
04-maze-move-only-failure1 AC 38 ms 2184 KB
04-maze-move-only-failure10 AC 36 ms 1680 KB
04-maze-move-only-failure2 AC 35 ms 1904 KB
04-maze-move-only-failure3 AC 35 ms 1816 KB
04-maze-move-only-failure4 AC 32 ms 1536 KB
04-maze-move-only-failure5 AC 33 ms 1676 KB
04-maze-move-only-failure6 AC 35 ms 1680 KB
04-maze-move-only-failure7 AC 34 ms 1692 KB
04-maze-move-only-failure8 AC 33 ms 1680 KB
04-maze-move-only-failure9 AC 35 ms 1940 KB
04-maze-move-only-success1 AC 37 ms 2064 KB
04-maze-move-only-success10 AC 36 ms 1672 KB
04-maze-move-only-success2 AC 35 ms 1812 KB
04-maze-move-only-success3 AC 36 ms 1684 KB
04-maze-move-only-success4 AC 34 ms 1572 KB
04-maze-move-only-success5 AC 34 ms 1676 KB
04-maze-move-only-success6 AC 35 ms 1684 KB
04-maze-move-only-success7 AC 35 ms 1680 KB
04-maze-move-only-success8 AC 34 ms 1684 KB
04-maze-move-only-success9 AC 35 ms 1932 KB
04-maze-random-failure1 AC 33 ms 1188 KB
04-maze-random-failure10 AC 33 ms 1296 KB
04-maze-random-failure2 AC 33 ms 1300 KB
04-maze-random-failure3 AC 33 ms 1316 KB
04-maze-random-failure4 AC 33 ms 1304 KB
04-maze-random-failure5 AC 31 ms 1300 KB
04-maze-random-failure6 AC 32 ms 1292 KB
04-maze-random-failure7 AC 33 ms 1292 KB
04-maze-random-failure8 AC 32 ms 1268 KB
04-maze-random-failure9 AC 32 ms 1300 KB
04-maze-random-success1 WA
04-maze-random-success10 WA
04-maze-random-success2 WA
04-maze-random-success3 WA
04-maze-random-success4 WA
04-maze-random-success5 WA
04-maze-random-success6 WA
04-maze-random-success7 WA
04-maze-random-success8 WA
04-maze-random-success9 WA
04-maze-simple-failure1 AC 32 ms 1296 KB
04-maze-simple-failure10 AC 31 ms 1312 KB
04-maze-simple-failure2 AC 31 ms 1300 KB
04-maze-simple-failure3 AC 33 ms 1300 KB
04-maze-simple-failure4 AC 33 ms 1304 KB
04-maze-simple-failure5 AC 32 ms 1296 KB
04-maze-simple-failure6 AC 32 ms 1288 KB
04-maze-simple-failure7 AC 33 ms 1292 KB
04-maze-simple-failure8 AC 33 ms 1300 KB
04-maze-simple-failure9 AC 33 ms 1420 KB
04-maze-simple-success1 AC 31 ms 1308 KB
04-maze-simple-success10 AC 33 ms 1296 KB
04-maze-simple-success2 AC 33 ms 1292 KB
04-maze-simple-success3 AC 33 ms 1296 KB
04-maze-simple-success4 AC 33 ms 1300 KB
04-maze-simple-success5 AC 39 ms 1300 KB
04-maze-simple-success6 AC 36 ms 1300 KB
04-maze-simple-success7 AC 36 ms 1312 KB
04-maze-simple-success8 AC 33 ms 1300 KB
04-maze-simple-success9 AC 36 ms 1428 KB
05-nest1 AC 33 ms 1300 KB
05-nest2 AC 40 ms 1308 KB
06-long1 AC 170 ms 20372 KB