이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "robot.h"
#include <bits/stdc++.h>
using namespace std;
// https://oj.uz/problem/view/IOI23_robot
constexpr int MAXS = 10;
/*
2 right
3 down
4 blocked
5 right skip
6 down skip
7 left skip
8 up skip
9 cleanup
*/
bool empty(int x) {
return x >= 0 && x != 4;
}
bool neighbor(int left, int down, int right, int up, vector<int> xs) {
for (int x : xs) {
if (left == x || down == x || right == x || up == x)
return true;
}
return false;
}
pair<char, int> dir(int self, int left, int down, int right, int up) {
// done
if (right == -2 && down == -2) {
if (left == 2) return { 'W', 1 };
if (up == 3) return { 'N', 1 };
if (left == 5) return { 'W', 1 };
if (up == 6) return { 'N', 1 };
}
if (left == -2 && up == -2) {
if (neighbor(left, down, right, up, { 1 })) {
if (right == 4) return { 'E', 9 };
if (down == 4) return { 'S', 9 };
return { 'T', 1 };
}
if (empty(right) && self < 2) return { 'E', 2 };
if (empty(down) && self < 3) return { 'S', 3 };
if (right >= 0 && (self < 5 || self == 9)) return { 'E', 5 };
if (down >= 0 && (self < 6 || self == 9)) return { 'S', 6 };
return { 'T', 19 };
}
if (neighbor(left, down, right, up, { 1 })) {
if (right == 4) return { 'E', 9 };
if (down == 4) return { 'S', 9 };
if (left == 2) return { 'W', 1 };
if (up == 3) return { 'N', 1 };
if (right == 7) return { 'E', 1 };
if (down == 8) return { 'S', 1 };
if (left == 5) return { 'W', 1 };
if (up == 6) return { 'N', 1 };
}
bool second_phase = neighbor(left, down, right, up, { 5, 6, 7, 8 });
if (empty(right) && !second_phase && self < 2) return { 'E', 2 };
if (empty(down) && !second_phase && self < 3) return { 'S', 3 };
if (up == 9 || right == 9) {
if (right == 4) return { 'E', 9 };
if (down == 4) return { 'S', 9 };
}
if (up == 9) return { 'N', 0 };
if (left == 9) return { 'W', 0 };
if (right >= 0 && right < 5 && second_phase && (self < 5 || self == 9)) return { 'E', 5 };
if (down >= 0 && down < 5 && second_phase && (self < 6 || self == 9)) return { 'S', 6 };
if (left >= 0 && left < 5 && second_phase && (self < 7 || self == 9)) return { 'W', 7 };
if (up >= 0 && up < 5 && second_phase && (self < 8 || self == 9)) return { 'N', 8 };
if (left == 2) return { 'W', 4 };
if (up == 3) return { 'N', 4 };
if (down == 8) return { 'S', 0 };
if (right == 7) return { 'E', 0 };
if (up == 6) return { 'N', 0 };
if (left == 5) return { 'W', 0 };
// unknown state
return { 'T', 19 };
}
void program_pulibot() {
vector<int> states;
for (int i = -2; i <= MAXS; ++i) states.push_back(i);
for (int l : states)
for (int d : states)
for (int r : states)
for (int u : states)
for (int s : states) {
char nd;
int ns;
tie(nd, ns) = dir(s, l, d, r, u);
set_instruction({ s, l, d, r, u }, ns, nd);
}
}
# | 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... |