#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int p[10001], depth[10001], ter[12];
int mx = 0;
void tternary() {
int val = 1;
while (val*3 < mx)
val *= 3;
vector<int> v;
do {
v.pb(mx/val);
mx %= val;
val /= 3;
} while (val > 1);
for (int i = 0; i < v.size(); i++) {
ter[i] = v[i];
}
}
int fternary(vector<int> v) {
int val = 1, num = 0;
for (int i = v.size()-1; i >= 0; i--) {
num += val*v[i];
val *= 3;
}
return num;
}
int send_message(int N, int i, int Pi) {
p[i] = Pi;
depth[i] = depth[Pi]+1;
if (i == N-11) {
for (int ind = 1; ind <= i; ind++)
if (depth[mx] < depth[ind])
mx = ind;
return 0;
}
if (i >= N-10) {
if (depth[i] > depth[mx])
return 4;
int pw = N-i;
return ter[pw];
}
return 0;
}
pair<int, int> longest_path(vector<int> S) {
for (int i = S.size()-1; i >= 1; i--) {
if (S[i] == 4)
return make_pair(0, i);
}
vector<int> teri;
for (int i = S.size()-10; i < S.size(); i++)
teri.pb(S[i]);
return make_pair(0, fternary(teri));
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |