Submission #1158563

#TimeUsernameProblemLanguageResultExecution timeMemory
1158563thieunguyenhuyRobot Contest (IOI23_robot)C++20
6 / 100
104 ms5988 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_36 = -15;
const int NOT_6 = -14;
const int NOT_5 = -13;
const int NOT_4 = -12;
const int NOT_3 = -11;
const int NOT_2 = -10;
const int NOT_1 = -9;
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 == int(S.size())) {
        set_instruction(S, Z, A);
        return;
    }

    if (S[index] == VIS) {
        for (int i = 1; i <= 6; ++i) {
            S[index] = i;
            backtrack(index + 1, S, Z, A);
        }
    }
    else if (S[index] == ANY) {
        for (int i = -2; i <= 6; ++i) {
            S[index] = i;
            backtrack(index + 1, S, Z, A);
        }
    }
    else if (S[index] == NOT_FREE) {
        for (int i = -2; i <= 6; ++i) if (i != FREE) {
            S[index] = i;
            backtrack(index + 1, S, Z, A);
        }
    }
    else if (S[index] == NOT_WALL) {
        for (int i = -2; i <= 6; ++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) if (i != 1 && i != 2) {
            S[index] = i;
            backtrack(index + 1, S, Z, A);
        }
    }
    else if (S[index] == NOT_PAR) {
        for (int i = -2; i <= 6; ++i) if (index <= 0 || i != order[(index + 1) % 4 + 1]) {
            S[index] = i;
            backtrack(index + 1, S, Z, A);
        }
    }
    else if (S[index] == NOT_1) {
        for (int i = -2; i <= 6; ++i) if (i != 1) {
            S[index] = i;
            backtrack(index + 1, S, Z, A);
        }
    }
    else if (S[index] == NOT_2) {
        for (int i = -2; i <= 6; ++i) if (i != 2) {
            S[index] = i;
            backtrack(index + 1, S, Z, A);
        }
    }
    else if (S[index] == NOT_3) {
        for (int i = -2; i <= 6; ++i) if (i != 3) {
            S[index] = i;
            backtrack(index + 1, S, Z, A);
        }
    }
    else if (S[index] == NOT_4) {
        for (int i = -2; i <= 6; ++i) if (i != 4) {
            S[index] = i;
            backtrack(index + 1, S, Z, A);
        }
    }
    else if (S[index] == NOT_5) {
        for (int i = -2; i <= 6; ++i) if (i != 5) {
            S[index] = i;
            backtrack(index + 1, S, Z, A);
        }
    }
    else if (S[index] == NOT_6) {
        for (int i = -2; i <= 6; ++i) if (i != 6) {
            S[index] = i;
            backtrack(index + 1, S, Z, A);
        }
    }
    else if (S[index] == NOT_36) {
        for (int i = -2; i <= 6; ++i) if (i != 3 && i != 6) {
            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, NOT_6, NOT_6, FREE, NOT_6}, 1, 'E');
    add({0, NOT_6, NOT_WALL, NOT_FREE, NOT_6}, 1, 'H');
    add({0, NOT_6, WALL, TRAP, NOT_6}, 1, 'H');
    add({0, NOT_6, WALL, VIS, NOT_6}, 1, 'H');

    add({1, NOT_6, FREE, NOT_6, NOT_6}, 2, 'S');
    add({1, NOT_6, NOT_FREE, NOT_6, NOT_6}, 2, 'H');
    
    add({2, 1, NOT_6, NOT_6, NOT_2}, 3, 'W');
    add({2, NOT_1, NOT_6, NOT_6, 2}, 3, 'N');

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

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

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

    add({6, NOT_6, 6, 3, NOT_6}, 6, 'E');
    add({3, ANY, ANY, 3, ANY}, 4, 'E');
    add({3, ANY, ANY, NOT_3, ANY}, 4, 'H');
    add({4, ANY, 3, NOT_3, ANY}, 5, 'S');
    add({4, ANY, NOT_3, NOT_3, ANY}, 5, 'H');
    add({5, 4, ANY, ANY, NOT_5}, 0, 'W');
    add({5, NOT_4, ANY, ANY, 5}, 0, 'N');
    add({5, 6, NOT_5, NOT_5, NOT_5}, 0, 'W');

    add({6, 6, NOT_36, NOT_36, NOT_36}, 1, 'W');
    add({6, NOT_36, 6, NOT_36, NOT_36}, 1, 'S');
    add({6, NOT_36, NOT_36, 6, NOT_36}, 1, 'E');
    add({6, NOT_36, NOT_36, NOT_36, 6}, 1, 'N');

    add({6, 1, WALL, WALL, NOT_VIS}, 1, 'T');
    add({6, 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...