Submission #49400

# Submission time Handle Problem Language Result Execution time Memory
49400 2018-05-28T10:11:08 Z georgerapeanu Easter Eggs (info1cup17_eastereggs) C++11
81 / 100
20 ms 540 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 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){
    nodes.clear();
    Map.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);

    int lo = 0,hi = (int)nodes.size() - 1;
    while(hi - lo > 0){
        int mid = (lo + hi) / 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:33:21: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
     return Map[que] = query(que);
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 248 KB Number of queries: 5
2 Incorrect 3 ms 308 KB Number of queries: 5
3 Incorrect 3 ms 392 KB Number of queries: 5
4 Incorrect 3 ms 392 KB Number of queries: 5
# Verdict Execution time Memory Grader output
1 Correct 5 ms 392 KB Number of queries: 9
2 Incorrect 7 ms 492 KB Number of queries: 10
3 Incorrect 11 ms 492 KB Number of queries: 10
4 Incorrect 13 ms 540 KB Number of queries: 10
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 540 KB Number of queries: 10
2 Incorrect 15 ms 540 KB Number of queries: 10
3 Incorrect 13 ms 540 KB Number of queries: 10
4 Incorrect 17 ms 540 KB Number of queries: 10