Submission #959809

#TimeUsernameProblemLanguageResultExecution timeMemory
959809GrindMachineRobot Contest (IOI23_robot)C++17
28 / 100
111 ms5972 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
 
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define REP(i,s,e) for(int i = s; i <= e; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
 
template<typename T>
void amin(T &a, T b) {
    a = min(a,b);
}
 
template<typename T>
void amax(T &a, T b) {
    a = max(a,b);
}
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif
 
/*
 
 
 
*/
 
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
 
#include "robot.h"
 
void program_pulibot()
{
    // set_instruction({0, -2, -1, 0, -2}, 1, 'E');
    // set_instruction({0, 1, -1, 0, -2}, 1, 'E');
    // set_instruction({0, 1, 0, -2, -2}, 1, 'S');
    // set_instruction({0, -1, -2, -2, 1}, 1, 'T');
 
    REP(c,-2,4){
        REP(w,-2,4){
            REP(s,-2,4){
                REP(e,-2,4){
                    REP(n,-2,4){
                        vector<int> v = {c,w,s,e,n};

                        int one_cnt = 0; 
                        int active = 0;

                        for(auto x : {c,w,s,e,n}){
                            one_cnt += (x == 1);
                            active += (x == 2);
                        }

                        if(c == 0){
                            set_instruction(v,2,'H');
                            conts;
                        }
                        
                        // if(one_cnt >= 2) conts;

                        bool backtrack = false;

                        // (n-1,m-1)
                        if(e == -2 and s == -2){
                            backtrack = true;
                        }
                        if(one_cnt) backtrack = true;

                        for(auto x : {c,w,s,e,n}){
                            if(x == 4) backtrack = true;
                        }

                        if(!backtrack){
                            // right
                            if(e == 0){
                                set_instruction(v,2,'E');
                            }
                            // left
                            else if(w == 0){
                                set_instruction(v,2,'W');
                            }
                            // up
                            else if(n == 0){
                                set_instruction(v,2,'N');
                            }
                            // down
                            else if(s == 0){
                                set_instruction(v,2,'S');
                            }
                            // if not both, then go back
                            else{
                                char ch = '?';
                                if(e == 2) ch = 'E';
                                if(w == 2) ch = 'W';
                                if(n == 2) ch = 'N';
                                if(s == 2) ch = 'S';
                                if(ch == '?') conts;
                                set_instruction(v,3,ch);
                            }
                        }
                        else{
                            // backtrack
                                
                            if(c < 0) conts;

                            int c2 = c;
                            if(c == 2) c2 = 1;
                            if(c == 3) c2 = 4;

                            // go to any 3 if it exists
                            if(e == 3){
                                set_instruction(v,c2,'E');
                            }
                            else if(w == 3){
                                set_instruction(v,c2,'W');
                            }
                            else if(n == 3){
                                set_instruction(v,c2,'N');
                            }
                            else if(s == 3){
                                set_instruction(v,c2,'S');
                            }
                            // otherwise, go to 4
                            else{
                                c2 = c;
                                if(c == 2) c2 = 1;
                                if(c > 2) c2 = 0;
                                char ch = '?';
                                if(e == 4) ch = 'E';
                                if(w == 4) ch = 'W';
                                if(n == 4) ch = 'N';
                                if(s == 4) ch = 'S';
                                if(ch != '?'){
                                    set_instruction(v,c2,ch);
                                }
                                // otherwise, go to 2
                                else{
                                    if(e == 2) ch = 'E';
                                    if(w == 2) ch = 'W';
                                    if(n == 2) ch = 'N';
                                    if(s == 2) ch = 'S';
                                    if(ch != '?'){
                                        set_instruction(v,c2,ch);                                
                                    }
                                    else{
                                        // (0,0)
                                        if(w == -2 and n == -2){
                                            set_instruction(v,1,'T');
                                            conts;
                                        }
                                        
                                        // otherwise, go to 1
                                        if(e == 1) ch = 'E';
                                        if(w == 1) ch = 'W';
                                        if(n == 1) ch = 'N';
                                        if(s == 1) ch = 'S';
                                        if(ch != '?'){
                                            set_instruction(v,c2,ch);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
#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...