Submission #518283

# Submission time Handle Problem Language Result Execution time Memory
518283 2022-01-23T10:16:48 Z lucri Easter Eggs (info1cup17_eastereggs) C++17
100 / 100
22 ms 376 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;
}*/
vector<int>l[520];
vector<int>q;
bool ok[520],part[520];
int nrp;
int constructie(int nod,int val)
{
    if(val==nrp)
        return val;
    for(auto x:l[nod])
    {
        if(part[x]==false)
        {
            part[x]=true;
            q.push_back(x);
            if(ok[x]==false)
                val=constructie(x,val+1);
            else
                val=constructie(x,val);
            if(val==nrp)
                return val;
        }
    }
    return val;
}
//int query(vector < int > islands);
int findEgg(int N, vector < pair < int, int > > bridges)
{
    for(int i=1;i<=N;++i)
    {
        ok[i]=false;
        while(!l[i].empty())
            l[i].pop_back();
    }
    for(auto x:bridges)
    {
        l[x.first].push_back(x.second);
        l[x.second].push_back(x.first);
    }
    nrp=N;
    while(nrp>1)
    {
        int nrramas=nrp;
        nrp/=2;
        nrramas-=nrp;
        q.push_back(1);
        part[1]=true;
        if(ok[1]==false)
            constructie(1,1);
        else
            constructie(1,0);
        if(query(q))
        {
            for(int i=1;i<=N;++i)
            {
                if(part[i]==false)
                    ok[i]=true;
                else
                    part[i]=false;
            }
        }
        else
        {
            for(int i=1;i<=N;++i)
            {
                if(part[i]==true)
                {
                    ok[i]=true;
                    part[i]=false;
                }
            }
            nrp=nrramas;
        }
        while(!q.empty())
            q.pop_back();
    }
    int ans=0;
    for(int i=1;i<=N;++i)
        if(ok[i]==false)
            ans=i;
    return ans;
}
/*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 Correct 1 ms 200 KB Number of queries: 4
2 Correct 1 ms 200 KB Number of queries: 4
3 Correct 1 ms 200 KB Number of queries: 4
4 Correct 1 ms 200 KB Number of queries: 4
# Verdict Execution time Memory Grader output
1 Correct 5 ms 340 KB Number of queries: 8
2 Correct 15 ms 340 KB Number of queries: 9
3 Correct 22 ms 300 KB Number of queries: 9
4 Correct 15 ms 328 KB Number of queries: 9
# Verdict Execution time Memory Grader output
1 Correct 21 ms 376 KB Number of queries: 9
2 Correct 15 ms 328 KB Number of queries: 9
3 Correct 22 ms 328 KB Number of queries: 9
4 Correct 16 ms 328 KB Number of queries: 9