# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1040918 | erray | 로봇 대회 (IOI23_robot) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
}
}
}
}
}
}
}