답안 #233803

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
233803 2020-05-21T18:26:53 Z medk 카멜레온의 사랑 (JOI20_chameleon) C++14
100 / 100
87 ms 632 KB
#include <bits/stdc++.h>
#include "chameleon.h"

#define ll long long
#define pb push_back
#define x first
#define y second
#define sz(u) (int)(u.size())
#define all(u) u.begin(),u.end()

using namespace std;

vector<vector<int>> g;

/*int Query(vector<int> qr)
{
    cout<<"he asked :";
    for(int x:qr) cout<<' '<<x;
    cout<<endl;
    int ret; cin>>ret;
    cout<<endl;
    return ret;
}

void Answer(int i, int j)
{
    cout<<"he answered "<<i<<' '<<j<<endl;
}*/

void genEdges(vector<int> v)
{
    vector<bool> queued(sz(v));
    vector<int> qu;
    for(int i=0;i<sz(v);i++)
    {
        bool flag=true;
        vector<int> to_query;
        for(int j=0;j<=i;j++)
        {
            if(queued[j]) continue;
            to_query.pb(v[j]);
        }
        while(1)
        {
            int get=Query(to_query);
            if(get==sz(to_query)) break;
            flag=false;
            int l=0,r=sz(to_query)-2;
            while(l<r)
            {
                int md=(l+r)/2+1;
                vector<int> toQ;
                for(int j=md;j<sz(to_query);j++)
                    toQ.pb(to_query[j]);
                get=Query(toQ);
                if(get==sz(toQ)) r=md-1;
                else l=md;
            }
            g[to_query[l]].pb(to_query.back());
            g[to_query.back()].pb(to_query[l]);
            to_query.erase(to_query.begin()+l);
        }
        if(!flag)
        {
            qu.pb(v[i]);
            queued[i]=1;
        }
    }
    for(int i=sz(v)-1;i>=0;i--)
    {
        if(!queued[i]) continue;
        vector<int> to_query;
        for(int j=sz(v)-1;j>=i;j--)
        {
            if(queued[j] && j!=i) continue;
            to_query.pb(v[j]);
        }
        while(1)
        {
            int get=Query(to_query);
            if(get==sz(to_query)) break;
            int l=0,r=sz(to_query)-2;
            while(l<r)
            {
                int md=(l+r)/2+1;
                vector<int> toQ;
                for(int j=md;j<sz(to_query);j++)
                    toQ.pb(to_query[j]);
                get=Query(toQ);
                if(get==sz(toQ)) r=md-1;
                else l=md;
            }
            g[to_query[l]].pb(to_query.back());
            g[to_query.back()].pb(to_query[l]);
            to_query.erase(to_query.begin()+l);
        }
    }
    if(sz(qu)) genEdges(qu);
}

void Solve(int N)
{
    g.resize(2*N+1);
    vector<int> tmp;
    for(int i=1;i<=2*N;i++) tmp.pb(i);
    genEdges(tmp);
    vector<bool> vis(2*N+1);
    for(int i=1;i<=2*N;i++)
    {
        if(vis[i]) continue;
        if(sz(g[i])==1)
        {
            Answer(i,g[i][0]);
            vis[g[i][0]]=1;
            vis[i]=1;
        }
    }
    for(int i=1;i<=2*N;i++)
    {
        if(vis[i]) continue;
        vector<int> candidates;
        for(int x:g[i]) if(!vis[x]) candidates.pb(x);
        if(sz(candidates)==1)
        {
            Answer(i,candidates[0]);
            vis[candidates[0]]=1;
            vis[i]=1;
        }
        else
        {
            for(int k=0;k<3;k++)
            {
                vector<int> ask;
                ask.pb(i);
                for(int j=0;j<3;j++)
                {
                    if(k==j) continue;
                    ask.pb(g[i][j]);
                }
                if(Query(ask)==1)
                {
                    vector<int> newask;
                    newask.pb(ask[1]);
                    for(int x:g[ask[1]])
                    {
                        if(x==i) continue;
                        newask.pb(x);
                    }
                    if(Query(newask)==1)
                    {
                        Answer(i,ask[2]);
                        vis[ask[2]]=1;
                    }
                    else
                    {
                        Answer(i,ask[1]);
                        vis[ask[1]]=1;
                    }
                    vis[i]=1;
                    break;
                }
            }
        }
    }
}
/*
int main()
{
    int N; cin>>N;
    Solve(N);
}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 34 ms 384 KB Output is correct
4 Correct 34 ms 384 KB Output is correct
5 Correct 34 ms 456 KB Output is correct
6 Correct 34 ms 504 KB Output is correct
7 Correct 35 ms 384 KB Output is correct
8 Correct 35 ms 512 KB Output is correct
9 Correct 35 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 84 ms 384 KB Output is correct
4 Correct 87 ms 424 KB Output is correct
5 Correct 85 ms 384 KB Output is correct
6 Correct 86 ms 384 KB Output is correct
7 Correct 86 ms 448 KB Output is correct
8 Correct 87 ms 384 KB Output is correct
9 Correct 84 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 34 ms 384 KB Output is correct
4 Correct 34 ms 384 KB Output is correct
5 Correct 34 ms 456 KB Output is correct
6 Correct 34 ms 504 KB Output is correct
7 Correct 35 ms 384 KB Output is correct
8 Correct 35 ms 512 KB Output is correct
9 Correct 35 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 84 ms 384 KB Output is correct
31 Correct 87 ms 424 KB Output is correct
32 Correct 85 ms 384 KB Output is correct
33 Correct 86 ms 384 KB Output is correct
34 Correct 86 ms 448 KB Output is correct
35 Correct 87 ms 384 KB Output is correct
36 Correct 84 ms 384 KB Output is correct
37 Correct 60 ms 384 KB Output is correct
38 Correct 37 ms 504 KB Output is correct
39 Correct 60 ms 384 KB Output is correct
40 Correct 59 ms 384 KB Output is correct
41 Correct 59 ms 384 KB Output is correct
42 Correct 34 ms 384 KB Output is correct
43 Correct 86 ms 632 KB Output is correct
44 Correct 60 ms 384 KB Output is correct
45 Correct 60 ms 384 KB Output is correct