Submission #518259

# Submission time Handle Problem Language Result Execution time Memory
518259 2022-01-23T09:15:02 Z lucri Easter Eggs (info1cup17_eastereggs) C++17
0 / 100
8 ms 456 KB
#include <bits/stdc++.h>
#include "grader.h"
using namespace std;

/*static int N, X, cntQ;
static vector < int > v[1009];

int query (vector < int > h)
{
    cntQ ++;
    int ap[1009];
    if (h.empty ()) return 0;
    for (int i=1; i<=N; i++)
        ap[i] = 0;
    for (auto it = h.begin (); it != h.end (); it ++)
        ap[*it] = 1;
    queue < int > cc;
    cc.push (h[0]), ap[h[0]] = 2;
    while (!cc.empty ())
    {
        int nod = cc.front ();
        cc.pop ();
        for (auto it = v[nod].begin (); it != v[nod].end (); it ++)
            if (ap[*it] == 1)
                ap[*it] = 2, cc.push (*it);
    }
    for (int i=1; i<=N; i++)
        if (ap[i] == 1) return -1;
    for (auto it = h.begin (); it != h.end (); it ++)
        if (*it == X) return 1;
    return 0;
}*/
int ve[520];
pair<int,int>l[520];
bool ok[520];
void constructie(int poz,int n)
{
    int nr=0;
    while(++nr<n)
    {
        ok[poz]=true;
        ve[++ve[0]]=poz;
        if(ok[l[poz].first]==true)
            poz=l[poz].second;
        else
            poz=l[poz].first;
    }
    ve[++ve[0]]=poz;
    return;
}
//int query(vector < int > islands);
int findEgg(int N, vector < pair < int, int > > bridges)
{
    ve[0]=0;
    int nra[520]={0};
    for(int i=1;i<=N;++i)
        ok[i]=false;
    for(auto x:bridges)
    {
        ++nra[x.first];
        ++nra[x.second];
        if(nra[x.first]==1)
            l[x.first].first=x.second;
        else
            l[x.first].second=x.second;
        if(nra[x.second]==1)
            l[x.second].first=x.first;
        else
            l[x.second].second=x.first;
    }
    for(int i=1;i<=N;++i)
    {
        if(nra[i]==1)
        {
            constructie(i,N);
            break;
        }
    }
    int b=1,e=N;
    while(b<=e)
    {
        int m=(b+e)/2;
        vector<int>q;
        for(int x=b;x<=m;++x)
            q.push_back(ve[x]);
        if(query(q))
            e=m-1;
        else
            b=m+1;
        while(!q.empty())
            q.pop_back();
    }
    return ve[b];
}
/*int main ()
{
freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
int Queries;
vector < pair < int, int > > param;
for (int i=1; i<N; i++)
{
    int x, y;
    scanf ("%d %d", &x, &y);
    v[x].push_back (y);
    v[y].push_back (x);
    param.push_back ({x, y});
}
scanf ("%d", &Queries);
while (Queries --)
{
    scanf ("%d", &X), cntQ = 0;
    int Y = findEgg (N, param);
    if (X != Y)
    {
        printf ("WA %d instead of %d\n", Y, X);
        return 0;
    }
    printf ("OK %d\n", cntQ);
}
return 0;
}*/
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 200 KB Number of queries: 5
2 Runtime error 1 ms 456 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 200 KB Number of queries: 9
2 Runtime error 1 ms 456 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 8 ms 200 KB Number of queries: 10
2 Runtime error 1 ms 456 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -