This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "robot.h"
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),_##i##_b=(b); i<=_##i##_b; i++)
#define SET(color, action) { set_instruction(state, color, action); continue; }
void subtask3() {
const int MAX_COLOR = 9;
const int BOUNDARY = -2;
const int BLOCKED = -1;
const int FINAL = 1;
// directions
const int ONE_SOUTH = 2;
const int ONE_EAST = 3;
const int ONE_NORTH = 4;
const int ONE_WEST = 5;
// phase 2
const int TWO_SOUTH = 6;
const int TWO_EAST = 7;
const int TWO_NORTH = 8;
const int TWO_WEST = 9;
FOR(cur,0,MAX_COLOR) FOR(west,-2,MAX_COLOR) FOR(south,-2,MAX_COLOR) FOR(east,-2,MAX_COLOR) FOR(north,-2,MAX_COLOR) {
vector<int> state {cur, west, south, east, north};
// Phase 3
if (cur == FINAL) {
if (south == BOUNDARY && east == BOUNDARY) SET(FINAL, 'T');
if (north >= 6) SET(FINAL, 'N');
if (south >= 6) SET(FINAL, 'S');
if (east >= 6) SET(FINAL, 'E');
if (west >= 6) SET(FINAL, 'W');
}
// Phase 2
if (north >= 6 || south >= 6 || east >= 6 || west >= 6 || cur >= 6) {
if (west == ONE_EAST) SET(cur >= 6 ? cur : cur + 4, 'W');
if (south == ONE_NORTH) SET(cur >= 6 ? cur : cur + 4, 'S');
if (east == ONE_WEST) SET(cur >= 6 ? cur : cur + 4, 'E');
if (north == ONE_SOUTH) SET(cur >= 6 ? cur : cur + 4, 'N');
if (north == BOUNDARY && west == BOUNDARY) SET(FINAL, 'H');
if (north == FINAL || south == FINAL || east == FINAL || west == FINAL) SET(FINAL, 'H');
if (cur == ONE_SOUTH || cur == TWO_SOUTH) SET(0, 'S');
if (cur == ONE_NORTH || cur == TWO_NORTH) SET(0, 'N');
if (cur == ONE_WEST || cur == TWO_WEST) SET(0, 'W');
if (cur == ONE_EAST || cur == TWO_EAST) SET(0, 'E');
}
// Reached final state
if (south == BOUNDARY && east == BOUNDARY) {
SET(6, 'H');
}
// Starting state
if (cur == 0 && north == BOUNDARY && west == BOUNDARY) {
if (south == 0) SET(ONE_SOUTH, 'S');
if (east == 0) SET(ONE_EAST, 'E');
}
// BFS
if (cur == ONE_SOUTH) {
if (east == 0 || east == ONE_WEST) SET(ONE_EAST, 'E');
if (north == 0 || north == ONE_SOUTH) SET(ONE_NORTH, 'N');
if (west == 0 || west == ONE_EAST) SET(ONE_WEST, 'W');
if (south == 0 || south == ONE_NORTH) SET(ONE_SOUTH, 'S');
}
if (cur == ONE_EAST) {
if (north == 0 || north == ONE_SOUTH) SET(ONE_NORTH, 'N');
if (west == 0 || west == ONE_EAST) SET(ONE_WEST, 'W');
if (south == 0 || south == ONE_NORTH) SET(ONE_SOUTH, 'S');
if (east == 0 || east == ONE_WEST) SET(ONE_EAST, 'E');
}
if (cur == ONE_NORTH) {
if (west == 0 || west == ONE_EAST) SET(ONE_WEST, 'W');
if (south == 0 || south == ONE_NORTH) SET(ONE_SOUTH, 'S');
if (east == 0 || east == ONE_WEST) SET(ONE_EAST, 'E');
if (north == 0 || north == ONE_SOUTH) SET(ONE_NORTH, 'N');
}
if (cur == ONE_WEST) {
if (south == 0 || south == ONE_NORTH) SET(ONE_SOUTH, 'S');
if (east == 0 || east == ONE_WEST) SET(ONE_EAST, 'E');
if (north == 0 || north == ONE_SOUTH) SET(ONE_NORTH, 'N');
if (west == 0 || west == ONE_EAST) SET(ONE_WEST, 'W');
}
if (cur == 0) {
if (north == ONE_SOUTH) SET(ONE_NORTH, 'N');
if (south == ONE_NORTH) SET(ONE_SOUTH, 'S');
if (east == ONE_WEST) SET(ONE_EAST, 'E');
if (west == ONE_EAST) SET(ONE_WEST, 'W');
}
}
}
void program_pulibot() {
subtask3();
}
Compilation message (stderr)
robot.cpp: In function 'void subtask3()':
robot.cpp:12:15: warning: unused variable 'BLOCKED' [-Wunused-variable]
12 | const int BLOCKED = -1;
| ^~~~~~~
# | 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... |