Submission #1157687

#TimeUsernameProblemLanguageResultExecution timeMemory
1157687thieunguyenhuy로봇 대회 (IOI23_robot)C++20
34 / 100
77 ms5820 KiB
#include "robot.h"

#include <bits/stdc++.h>
using namespace std;

#define POPCOUNT(n) (__builtin_popcountll((n)))
#define CLZ(n) (__builtin_clzll((n)))
#define CTZ(n) (__builtin_ctzll((n)))
#define LOG(n) (63 - __builtin_clzll((n)))
#define BIT(n, i) (((n) >> (i)) & 1ll)
#define MASK(i) (1ll << (i))
#define FLIP(n, i) ((n) ^ (1ll << (i)))
#define ON(n, i) ((n) | MASK(i))
#define OFF(n, i) ((n) & ~MASK(i))

#define Int __int128
#define fi first
#define se second

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long, long long>> vll;
typedef vector<pair<long long, int>> vli;
typedef vector<pair<int, long long>> vil;

template <class T1, class T2> bool maximize(T1 &x, T2 y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}
template <class T1, class T2> bool minimize(T1 &x, T2 y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}

template <class T> void remove_duplicate(vector<T> &ve) {
    sort (ve.begin(), ve.end());
    ve.resize(unique(ve.begin(), ve.end()) - ve.begin());
}

mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
template <class T1, class T2> T1 random(T1 l, T2 r) {
    return uniform_int_distribution<T1>(l, r)(rng);
}
template <class T> T random(T r) {
    return rng() % r;
}

const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const long long INF = 1e18;

const char dir[] = {'H', 'W', 'S', 'E', 'N'};
const int order[] = {-1, 3, 2, 1, 4};

const int NOT_PAR = -8;
const int NOT_VIS = -7;
const int NOT_WALL = -6;
const int VIS = -5;
const int NOT_FREE = -4;
const int ANY = -3;
const int WALL = -2;
const int TRAP = -1;
const int FREE = 0;

void backtrack(int index, vector<int> S, int Z, char A) {
    if (index == S.size()) {
        set_instruction(S, Z, A);
        return;
    }

    if (S[index] == VIS) {
        for (int i = 1; i <= 4; ++i) {
            S[index] = i;
            backtrack(index + 1, S, Z, A);
        }
    }
    else if (S[index] == ANY) {
        for (int i = -2; i <= 4; ++i) {
            S[index] = i;
            backtrack(index + 1, S, Z, A);
        }
    }
    else if (S[index] == NOT_FREE) {
        for (int i = -2; i <= 4; ++i) if (i != FREE) {
            S[index] = i;
            backtrack(index + 1, S, Z, A);
        }
    }
    else if (S[index] == NOT_WALL) {
        for (int i = -2; i <= 4; ++i) if (i != WALL) {
            S[index] = i;
            backtrack(index + 1, S, Z, A);
        }
    }
    else if (S[index] == NOT_VIS) {
        for (int i = -2; i <= 0; ++i) {
            S[index] = i;
            backtrack(index + 1, S, Z, A);
        }
    }
    else if (S[index] == NOT_PAR) {
        for (int i = -2; i <= 4; ++i) if (index <= 0 || i != order[(index + 1) % 4 + 1]) {
            S[index] = i;
            backtrack(index + 1, S, Z, A);
        }
    }
    else backtrack(index + 1, S, Z, A);
}

void add(vector<int> S, int Z, char A) {
    backtrack(0, S, Z, A);
}

void program_pulibot() {
    // Old order: WSEN -> Bad
    // New order: ESWN -> Should be better

    add({0, ANY, ANY, FREE, ANY}, 1, 'E');
    add({0, ANY, NOT_WALL, NOT_FREE, ANY}, 1, 'H');
    add({0, ANY, WALL, TRAP, ANY}, 1, 'H');
    add({0, ANY, WALL, VIS, ANY}, 1, 'H');

    add({1, ANY, FREE, ANY, ANY}, 2, 'S');
    add({1, ANY, NOT_FREE, ANY, ANY}, 2, 'H');
    
    add({2, FREE, ANY, ANY, ANY}, 3, 'W');
    add({2, NOT_FREE, ANY, ANY, ANY}, 3, 'H');
    
    add({3, ANY, ANY, ANY, FREE}, 4, 'N');
    add({3, ANY, ANY, ANY, NOT_FREE}, 4, 'H');
    
    add({4, NOT_PAR, NOT_PAR, 3, NOT_PAR}, 0, 'E');
    add({4, NOT_PAR, 4, NOT_PAR, NOT_PAR}, 0, 'S');
    add({4, 1, NOT_PAR, NOT_PAR, NOT_PAR}, 0, 'W');
    add({4, NOT_PAR, NOT_PAR, NOT_PAR, 2}, 0, 'N');

    add({0, VIS, WALL, WALL, NOT_VIS}, 5, 'W');
    add({0, NOT_VIS, WALL, WALL, VIS}, 5, 'N');

    for (int five = 1; five <= 4; ++five) {
        for (int par = 1; par <= 4; ++par) if (par != five) {
            vector<int> S(5);
            S[0] = order[five], S[1] = S[2] = S[3] = S[4] = NOT_PAR;
            S[five] = 5, S[par] = order[(par + 1) % 4 + 1];
            add(S, 5, dir[par]);
        }
    }

    add({2, WALL, 5, NOT_VIS, WALL}, 5, 'H');
    add({1, WALL, NOT_VIS, 5, WALL}, 5, 'H');

    add({5, 5, ANY, ANY, ANY}, 1, 'W');
    add({5, ANY, 5, ANY, ANY}, 1, 'S');
    add({5, ANY, ANY, 5, ANY}, 1, 'E');
    add({5, ANY, ANY, ANY, 5}, 1, 'N');

    add({5, 1, WALL, WALL, NOT_VIS}, 1, 'T');
    add({5, NOT_VIS, WALL, WALL, 1}, 1, 'T');
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...