Submission #49401

# Submission time Handle Problem Language Result Execution time Memory
49401 2018-05-28T10:15:19 Z georgerapeanu Easter Eggs (info1cup17_eastereggs) C++11
81 / 100
12 ms 600 KB
#include <bits/stdc++.h>
#include "grader.h"

using namespace std;

vector<int> G[600];
vector<int> nodes;


void linearize(int node,int father){
    nodes.push_back(node);
    for(auto it:G[node]){
        if(it != father){
            linearize(it,node);
            nodes.push_back(node);
        }
    }
}

vector<int> que;
map< vector<int> , int > Map;
bool done = 0;


bool ok(int le,int ri){
    que.clear();
    for(int i = le;i <= ri;i++){
        que.push_back(nodes[i]);
    }
    sort(que.begin(),que.end());
    que.resize(unique(que.begin(),que.end()) - que.begin());
    if(Map.count(que)){
        return Map[que];
    }
    return Map[que] = query(que);
}

int findEgg (int N, vector < pair < int, int > > bridges){
    Map.clear();
    if(!done){
        nodes.clear();
        for(int i = 1;i <= N;i++){
            G[i].clear();
        }
        for(auto it:bridges){
            G[it.first].push_back(it.second);
            G[it.second].push_back(it.first);
        }

        linearize(1,0);

        done = 1;
    }

    int lo = 0,hi = (int)nodes.size() - 1;
    while(hi - lo > 0){
        int mid = (lo + hi - 1) / 2;
        if(ok(lo,mid)){
            hi = mid;
        }
        else{
            lo = mid + 1;
        }
    }
    return nodes[lo];
}

Compilation message

eastereggs.cpp: In function 'bool ok(int, int)':
eastereggs.cpp:35:21: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
     return Map[que] = query(que);
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 248 KB Number of queries: 5
2 Incorrect 2 ms 308 KB Number of queries: 5
3 Incorrect 3 ms 512 KB Number of queries: 5
4 Incorrect 3 ms 512 KB Number of queries: 5
# Verdict Execution time Memory Grader output
1 Correct 7 ms 540 KB Number of queries: 9
2 Incorrect 9 ms 540 KB Number of queries: 10
3 Incorrect 12 ms 540 KB Number of queries: 10
4 Incorrect 9 ms 600 KB Number of queries: 10
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 600 KB Number of queries: 10
2 Incorrect 10 ms 600 KB Number of queries: 10
3 Incorrect 12 ms 600 KB Number of queries: 10
4 Incorrect 9 ms 600 KB Number of queries: 10