Submission #408745

#TimeUsernameProblemLanguageResultExecution timeMemory
408745LptN21Poklon (COCI17_poklon7)C++14
48 / 120
586 ms170408 KiB
#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)

poklon.cpp: In function 'int main()':
poklon.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
poklon.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         scanf("%d%d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...