# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1077077 | Trent | Beech Tree (IOI23_beechtree) | C++17 | 1 ms | 348 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(r, N) {
vi v = sub(r, P);
sort(all(v));
bool found = false;
do {
bool can = v[0] == r;
map<int, int> freq;
REP(i, 1, v.size()) {
P[v[i]] = v[freq[C[v[i]]]];
freq[C[v[i]]] += 1;
}
found = found || can;
} while(next_permutation(all(v)));
ret[r] = found ? 1 : 0;
}
return ret;
}
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;
}
Compilation message (stderr)
# | 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... |
# | 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... |