| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1077073 | Trent | Robot Contest (IOI23_robot) | C++17 | 0 ms | 0 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "beechtree.h"
#include "bits/stdc++.h"
using namespace std;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) x.begin(), x.end()
#define asst(x) if(!(x)) exit(2)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
vi sub(int T, vi& P) {
    set<int> in;
    in.insert(T);
    int N = P.size();
    while(true) {
        bool hasNew = false;
        forR(i, N) {
            if(in.count(P[i]) && !in.count(i)) {
                hasNew = true;
                in.insert(i);
            }
        }
        if(!hasNew) break;
    }
    vi ret;
    for(int i : in) ret.push_back(i);
    return ret;
}
std::vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C)
{
    vi ret(N);
    if(N <= 8) {
        forR(i, N) {
            vi vals = sub(i, P);
            sort(all(vals));
            bool found = false;
            do {
                bool can = vals[0] == i;
                map<int, int> freq;
                for(int j : vals) {
                    can = can && P[j] == vals[freq[C[j]]];
                    ++freq[C[j]];
                }
                found = found || can;
            } while(next_permutation(all(vals)));
            ret[i] = found;
        }
    }
    bool can = true;
    int lasCol = -1;
    for(int i = N-1; i >= 0; --i) {
        if(can) {
            ret[i] = 1;
            if(lasCol == -1) lasCol = C[i];
            else can = can && C[i] == lasCol;
        } else {
            ret[i] = 0;
        }
    }
    return ret;
}
