Submission #945070

# Submission time Handle Problem Language Result Execution time Memory
945070 2024-03-13T11:24:19 Z Tuanlinh123 Chameleon's Love (JOI20_chameleon) C++17
100 / 100
24 ms 564 KB
#include "chameleon.h"
#include<bits/stdc++.h>
#define ll int
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
#define sz(a) ((ll)(a).size())
using namespace std;

void Solve(ll n) 
{
    vector <vector <ll>> sus(n*2+1);
    vector <ll> love(n*2+1, 0), loved(n*2+1, 0), res(n*2+1, 0), col(n*2+1, 0);
    auto change=[&](ll s)
    {
        queue <ll> q;
        vector <bool> check(n*2+1, 0);
        check[s]=1, col[s]^=1, q.push(s);
        while (!q.empty())
        {
            ll u=q.front(); q.pop();
            for (ll v:sus[u])
                if (!check[v])
                    check[v]=1, col[v]^=1, q.push(v);
        }
    };
    auto addedge=[&](ll u, ll v)
    {
        if (col[u]==col[v]) change(u);
        sus[u].pb(v), sus[v].pb(u);
    };
    auto ask=[&](vector <ll> q, ll o) 
    {
        q.pb(o); 
        return (Query(q)!=sz(q));
    };
    for (ll i=1; i<=n*2; i++)
    {
        vector <ll> num[2];
        for (ll j=1; j<i; j++) num[col[j]].pb(j);
        for (ll j=0; j<2; j++)
        {
            if (!sz(num[j])) continue;
            ll p=0, en=sz(num[j]);
            while (p<en)
            {
                if (!ask(vector <ll>(num[j].begin()+p, num[j].end()), i)) break;
                ll lo=p, hi=en-1;
                while (hi>lo)
                {
                    ll mid=(lo+hi+1)/2;
                    if (!ask(vector <ll>(num[j].begin()+lo, num[j].begin()+mid), i))
                        lo=mid;
                    else hi=mid-1;
                }
                addedge(i, num[j][lo]), p=lo+1;
            }
        }
    }
    for (ll i=1; i<=n*2; i++)
    {
        if (sz(sus[i])==1)
        {
            res[i]=sus[i][0], res[sus[i][0]]=i;
            continue;
        }
        assert(sz(sus[i])==3);
        for (ll j=0; j<3; j++)
            if (Query(vector <ll>{i, sus[i][j], sus[i][(j+1)%3]})==1)
                love[i]=sus[i][(j+2)%3], loved[sus[i][(j+2)%3]]=i;
    }
    for (ll i=1; i<=n*2; i++)
    {
        if (sz(sus[i])==1) continue;
        for (ll j:sus[i])
            if (j!=love[i] && j!=loved[i])
                res[i]=j, res[j]=i;
    }
    for (ll i=1; i<=n*2; i++)
    {
        if (!res[i]) continue;
        Answer(i, res[i]), res[i]=res[res[i]]=0;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 11 ms 532 KB Output is correct
4 Correct 11 ms 344 KB Output is correct
5 Correct 11 ms 344 KB Output is correct
6 Correct 11 ms 344 KB Output is correct
7 Correct 11 ms 344 KB Output is correct
8 Correct 11 ms 344 KB Output is correct
9 Correct 11 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 21 ms 344 KB Output is correct
4 Correct 21 ms 344 KB Output is correct
5 Correct 21 ms 344 KB Output is correct
6 Correct 22 ms 564 KB Output is correct
7 Correct 24 ms 344 KB Output is correct
8 Correct 22 ms 344 KB Output is correct
9 Correct 23 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 11 ms 532 KB Output is correct
4 Correct 11 ms 344 KB Output is correct
5 Correct 11 ms 344 KB Output is correct
6 Correct 11 ms 344 KB Output is correct
7 Correct 11 ms 344 KB Output is correct
8 Correct 11 ms 344 KB Output is correct
9 Correct 11 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 21 ms 344 KB Output is correct
31 Correct 21 ms 344 KB Output is correct
32 Correct 21 ms 344 KB Output is correct
33 Correct 22 ms 564 KB Output is correct
34 Correct 24 ms 344 KB Output is correct
35 Correct 22 ms 344 KB Output is correct
36 Correct 23 ms 340 KB Output is correct
37 Correct 22 ms 344 KB Output is correct
38 Correct 11 ms 344 KB Output is correct
39 Correct 22 ms 344 KB Output is correct
40 Correct 22 ms 344 KB Output is correct
41 Correct 22 ms 344 KB Output is correct
42 Correct 11 ms 552 KB Output is correct
43 Correct 24 ms 344 KB Output is correct
44 Correct 22 ms 344 KB Output is correct
45 Correct 22 ms 556 KB Output is correct