#include "robot.h"
#include<bits/stdc++.h>
using namespace std;
const string dir="HWSEN";
const int nothing=-4;
const int boundary=-3;
const int obstacle=-2;
const int blank=-1;
const int path=0;
const int west=1;
const int south=2;
const int east=3;
const int north=4;
int pos=0;
pair<char,int>make_move(int d){
return {dir[d],d};
}
int prv(int d){
return (d+1)%4+1;
}
int nxt(int d){
return d%4+1;
}
pair<char,int>get(vector<int>S){
for(int i=0;i<5;++i)
--S[i];
bool Start=(S[west]==boundary&&S[north]==boundary);
bool End=(S[east]==boundary&&S[south]==boundary);
if(S[pos]==blank){
if(Start){
if(S[south]==blank)
return make_move(south);
if(S[east]==blank)
return make_move(east);
return {'-',nothing};
}
if(End)
return {'H',east};
for(int nd=1;nd<5;++nd)
if(S[nd]==prv(nd))
return make_move(nd);
return {'-',nothing};
}
if(S[pos]<=path)
return {'-',nothing};
if(S[pos]==prv(S[pos])){
int nd=nxt(S[pos]);
while(S[nd]!=blank&&S[nd]!=prv(nd))
nd=nxt(nd);
return make_move(nd);
}
for(int nd=1;nd<5;++nd)
if(S[nd]==prv(nd))
return {dir[nd],S[pos]};
if(Start||count(S.begin(),S.end(),path)>0){
if(End)
return {'T',path};
else
return {dir[S[pos]],path};
}
return {dir[S[pos]],blank};
}
void program_pulibot(){
vector<int>S(5);
for(S[0]=-2;S[0]<=5;++S[0])
for(S[1]=-2;S[1]<=5;++S[1])
for(S[2]=-2;S[2]<=5;++S[2])
for(S[3]=-2;S[3]<=5;++S[3])
for(S[4]=-2;S[4]<=5;++S[4]){
auto[A,Z]=get(S);
if(Z!=-4)
set_instruction(S,Z+1,A);
}
}
# | 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... |