# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
408745 | LptN21 | Poklon (COCI17_poklon7) | C++14 | 586 ms | 170408 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 <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define FF first
#define SS second
#define pb push_back
#define sz(x) (int)x.size()
#define oo 1e18
#define eps 1e-9
#define PI acos(-1.0)
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
const int N = 1e6+7, M=20+7;
const int MOD = 1e9+7;
int n, m, k, t;
ll ans=0;
int val[N*3];
vector<int> adj[N*3];
void dfs(int u, int depth=0) {
if(!sz(adj[u])) {
ans=max(ans, 1LL*val[u]*(1<<depth));
return;
}
for(int v, i=0;i<sz(adj[u]);i++) v=adj[u][i], dfs(v, depth+1);
}
void print() {
vector<int> s;
while(ans) s.pb(ans&1LL), ans>>=1LL;
for(int i=sz(s)-1;i>=0;i--) printf("%d", s[i]);
}
signed main() {
//freopen("test.inp", "r", stdin);
//freopen("test.out", "w", stdout);
//fastIO;
scanf("%d", &n);
int u, v, r=n;
for(int i=1;i<=n;i++) {
scanf("%d%d", &u, &v);
if(u<0) {
val[++r]=-u;
adj[i].pb(r);
} else adj[i].pb(u);
if(v<0) {
val[++r]=-v;
adj[i].pb(r);
} else adj[i].pb(v);
}
dfs(1), print();
return 0;
}
/* stuff you should look for
- int overflow, array bounds
- special cases (n=1?)
- do smth instead of do nothing and stay organized
- WRITE STUFF DOWN
- DONT JUST STICK ON ONE APPROACH
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |