#include <bits/stdc++.h>
using namespace std;
int adj[10000];
int d[10000];
int dmax = 0;
int last0 = 0;
int last = 0;
string s = "", s1, s2;
void f( int n ) {
if ( n == 0 ) {
s = "0";
return;
}
while ( n > 0 ) {
s += char( ( n % 4 ) + '0' );
n /= 4;
}
return;
}
int send_message ( int n, int i, int pi ) {
int d1[i + 1];
queue <int> q;
adj[i] = pi;
d[i] = d[pi] + 1;
if ( d[i] > d[last0] ) {
last0 = i;
}
d1[last0] = 0;
q.push( last0 );
dmax = 0;
while ( q.size() ) {
int x = q.front();
q.pop();
if ( x == 0 ) {
continue;
}
int y = adj[x];
q.push( y );
d1[y] = d1[x] + 1;
if ( d1[y] > dmax ) {
dmax = d1[y];
last = y;
} else if ( d1[y] == dmax ) {
last = min( last, d1[y] );
}
}
if ( i == 9985 ) {
f( last0 );
s1 = s;
s = "";
while ( s1.length() < 7 ) {
s1 += "0";
}
f( last );
s2 = s;
} else if ( i > 9985 and i < 9993 ) {
if ( last0 == i or last == i ) {
if ( last0 == 0 or last == 0 ) {
return 4;
} else {
return last + last0;
}
} else {
return s1[i - 9986] - '0';
}
} else if ( i > 9992 ) {
if ( last0 == i or last == i ) {
if ( last0 == 0 or last == 0 ) {
return 4;
} else {
return last + last0;
}
} else {
return s2[i - 9993] - '0';
}
}
return 0;
}
pair <int, int> longest_path ( vector <int> a ) {
pair <int, int> answer = {0, 0};
int k = 1;
bool b = false;
for ( int i = 9986; i < 10000; i++ ) {
if ( a[i] == 4 ) {
answer = { 0, i };
b = true;
} else if ( a[i] > 4 ) {
answer = { min( a[i] - i, i ), max( a[i] - i, i ) };
b = true;
} else if ( b == false ) {
if ( i > 9992 ) {
answer.second += a[i] * k;
} else {
answer.first += a[i] * k;
}
if ( i == 9992 ) {
k = 1;
} else {
k *= 4;
}
}
}
return answer;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |