#include "robot.h"
#include <bits/stdc++.h>
using namespace std;
enum {B=0,P=1,N=2,E=3,S=4,W=5};
int rot_ccw(int c){
if(c==N) return W;
if(c==W) return S;
if(c==S) return E;
if(c==E) return N;
return c;
}
int dx[6]={0,0,-1,0,1,0};
int dy[6]={0,0,0,1,0,-1};
char mv[6]={'T','T','N','E','S','W'};
void add(array<int,5> s,int z,char a){
set_instruction({s[0],s[1],s[2],s[3],s[4]},z,a);
}
void program_pulibot(){
for(int c=0;c<6;c++)
for(int n=0;n<6;n++)
for(int e=0;e<6;e++)
for(int s=0;s<6;s++)
for(int w=0;w<6;w++){
array<int,5> st={c,n,e,s,w};
// ===== PHASE 1 =====
// start cell special kick
if(c==B && n==-2 && w==-2){
if(s!= -1) add(st,S,'S');
else add(st,E,'E');
continue;
}
// if on arrow: rotate until blank or back arrow
if(c>=N){
int d=c;
for(int k=0;k<4;k++){
int nc=rot_ccw(d);
int neigh = (nc==N?n: nc==E?e: nc==S?s:w);
if(neigh==B || neigh==(rot_ccw(rot_ccw(nc)))){
add(st,c,mv[nc]);
goto done;
}
d=nc;
}
}
// if on blank: follow parent arrow
if(c==B){
if(n==S) add(st,N,'N');
else if(e==W) add(st,E,'E');
else if(s==N) add(st,S,'S');
else if(w==E) add(st,W,'W');
else add(st,B,'T');
continue;
}
// ===== PHASE 2 =====
if(c>=N){
int d=c;
add(st,B,mv[d]);
continue;
}
if(c==B || c==P){
bool nearPath = (n==P||e==P||s==P||w==P);
if(nearPath) add(st,P,'T');
else add(st,B,'T');
continue;
}
done:;
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |