# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1040918 | erray | Robot Contest (IOI23_robot) | C++17 | 0 ms | 0 KiB |
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;
#ifdef DEBUG
#include "/home/ioi/contests/ioi23_d2/debug.h"
#else
#define debug(...) void(37)
#endif
int Z = 5;
enum {
BOUNDARY = -2,
OBSTACLE = -1,
CLEAN = 0,
PATH = 1,
WEST = 2,
SOUTH = 3,
EAST = 4,
NORTH = 5
};
using I = pair<int, char>;
I invalid{-1, 'Ğ'};
I get_instruction(int m, int w, int s, int e, int n) {
auto Adj = [&](int x) {
return (w == x) + (s == x) + (e == x) + (n == x);
};
auto Next = [&] -> I {
int start = (m >= WEST ? m - WEST + 1 : 0);
for (int i = 0; i < 4; ++i) {
int cur = WEST + (start + i) % 4;
if (cur == WEST && w == EAST) {
return {WEST, 'W'};
}
if (cur == SOUTH && s == NORTH) {
return {SOUTH, 'S'};
}
if (cur == EAST && e == WEST) {
return {EAST, 'E'};
}
if (cur == NORTH && n == SOUTH) {
return {NORTH, 'N'};
}
}
return invalid;
};
auto Next_and_explore = [&] -> I {
int start = (m >= WEST ? m - WEST + 1 : 0);
for (int i = 0; i < 4; ++i) {
int cur = WEST + (start + i) % 4;
if (cur == WEST && (w == EAST || w == CLEAN)) {
return {WEST, 'W'};
}
if (cur == SOUTH && (s == NORTH || s == CLEAN)) {
return {SOUTH, 'S'};
}
if (cur == EAST && (e == WEST || e == CLEAN)) {
return {EAST, 'E'};
}
if (cur == NORTH && (n == SOUTH || n == CLEAN)) {
return {NORTH, 'N'};
}
}
return invalid;
};
auto Clean = [&] -> I {
if (m == WEST) return {CLEAN, 'W'};
if (m == SOUTH) return {CLEAN, 'S'};
if (m == EAST) return {CLEAN, 'E'};
if (m == NORTH) return {CLEAN, 'N'};
return invalid;
};
auto Path = [&] -> I {
if (m == WEST) return {PATH, 'W'};
if (m == SOUTH) return {PATH, 'S'};
if (m == EAST) return {PATH, 'E'};
if (m == NORTH) return {PATH, 'N'};
return invalid;
};
auto Is_betrayal = [&] {
if (m == WEST && w != EAST) return true;
if (m == SOUTH && s != NORTH) return true;
if (m == EAST && e != WEST) return true;
if (m == NORTH && n != SOUTH) return true;
return false;
};
if (m < 0) return invalid;
// 0 0
if (n == BOUNDARY && w == BOUNDARY) {
if (m == CLEAN) {
if (s == CLEAN) {
return {SOUTH, 'S'};
}
if (e == CLEAN) {
return {EAST, 'E'};
}
return invalid;
}
if (Is_betrayal()) {
auto n = Next();
if (n == invalid) return Path();
else {
n.first = m;
return n;
}
}
}
// N - 1 N - 1
if (s == BOUNDARY && e == BOUNDARY) {
if (m == CLEAN) {
auto go = Next();
if (go == invalid) return invalid;
go.first = EAST; //betrayal
return go;
} else {
return {PATH, 'T'};
}
}
//newly explored
if (m == CLEAN) {
return Next();
}
//start cleaning and painting
if (Is_betrayal()) {
auto n = Next();
if (n == invalid) {
if (Adj(PATH)) return Path();
else return Clean();
} else {
n.first = m;
return n;
}
}
//explore
return Next_and_explore();
}
void program_pulibot() {
for (int me = -2; me <= Z; ++me) {
for (int w = -2; w <= Z; ++w) {
for (int s = -2; s <= Z; ++s) {
for (int e = -2; e <= Z; ++e) {
for (int n = -2; n <= Z; ++n) {
auto i = get_instruction(me, w, s, e, n);
if (i != invalid) {
set_instruction({me, w, s, e, n}, i.first, i.second);
}
}
}
}
}
}
}