Submission #921129

# Submission time Handle Problem Language Result Execution time Memory
921129 2024-02-03T10:34:47 Z vjudge1 Chameleon's Love (JOI20_chameleon) C++17
100 / 100
55 ms 616 KB
#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
    vector <int> ve[1001],tmp,V[2];
    int L[1001],c[1001],vis[1001],done[1001];
}
int get(int i, int l, int r, vector <int> v){
    tmp.clear();
    tmp.push_back(i);
    for (int i=l;i<=r;i++)
        tmp.push_back(v[i]);
    if (Query(tmp)==r-l+2)
        return -1;
    int lo=l,hi=r-1,kq=r;
    while (lo<=hi){
        int mid=(lo+hi)>>1;
        tmp.clear();
        tmp.push_back(i);
        for (int i=l;i<=mid;i++)
            tmp.push_back(v[i]);
        if (Query(tmp)<mid-l+2){
            kq=mid;
            hi=mid-1;
        }
        else
            lo=mid+1;
    }
    return kq;
}
vector <int> getall(int i, vector <int> v){
    int cur=0;
    vector <int> res;
    while (cur<v.size()&&res.size()<3){
        cur=get(i,cur,v.size()-1,v);
        if (cur==-1)
            break;
        res.push_back(v[cur]);
        cur++;
    }
    return res;
}
vector <int> operator +(vector <int> a, vector <int> b){
    for (int i:b)
        a.push_back(i);
    return a;
}
void dfs(int u, int C){
    if (vis[u])
        return;
    vis[u]=1;
    c[u]=C;
    V[C].push_back(u);
    for (int v:ve[u])
        dfs(v,C^1);
}
void Solve(int N){
    for (int i=1;i<=N*2;i++){
        memset(vis,0,sizeof(vis));
        memset(c,0,sizeof(c));
        V[0].clear();
        V[1].clear();
        for (int j=1;j<i;j++)
            if (!vis[j])
                dfs(j,0);
        ve[i]=getall(i,V[0])+getall(i,V[1]);
        for (int j:ve[i])
            ve[j].push_back(i);
    }
    for (int i=1;i<=N*2;i++){
        if (ve[i].size()==1){
            if (ve[i][0]>i){
                Answer(i,ve[i][0]);
                done[i]=done[ve[i][0]]=1;
            }
            continue;
        }
        if (Query({i,ve[i][0],ve[i][1]})<2){
            L[ve[i][2]]=i;
            continue;
        }
        if (Query({i,ve[i][0],ve[i][2]})<2){
            L[ve[i][1]]=i;
            continue;
        }
        L[ve[i][0]]=i;
    }
    for (int i=1;i<=N*2;i++){
        if (ve[i].size()>1&&L[i]&&!done[i]){
            vector <int> tmp={i,L[i]};
            for (int j:ve[i])
                if (j!=L[i])
                    tmp.push_back(j);
            int x=tmp.back();
            tmp.pop_back();
            int j=Query(tmp)<2?tmp.back():x;
            done[i]=done[j]=1;
            Answer(i,j);
            continue;
        }
    }
}

Compilation message

chameleon.cpp: In function 'std::vector<int> getall(int, std::vector<int>)':
chameleon.cpp:34:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     while (cur<v.size()&&res.size()<3){
      |            ~~~^~~~~~~~~
# 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 20 ms 600 KB Output is correct
4 Correct 23 ms 588 KB Output is correct
5 Correct 20 ms 600 KB Output is correct
6 Correct 20 ms 600 KB Output is correct
7 Correct 20 ms 600 KB Output is correct
8 Correct 20 ms 600 KB Output is correct
9 Correct 20 ms 576 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 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 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 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 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 344 KB Output is correct
11 Correct 1 ms 356 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 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 1 ms 344 KB Output is correct
3 Correct 42 ms 616 KB Output is correct
4 Correct 48 ms 600 KB Output is correct
5 Correct 42 ms 608 KB Output is correct
6 Correct 43 ms 584 KB Output is correct
7 Correct 42 ms 608 KB Output is correct
8 Correct 46 ms 604 KB Output is correct
9 Correct 47 ms 600 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 20 ms 600 KB Output is correct
4 Correct 23 ms 588 KB Output is correct
5 Correct 20 ms 600 KB Output is correct
6 Correct 20 ms 600 KB Output is correct
7 Correct 20 ms 600 KB Output is correct
8 Correct 20 ms 600 KB Output is correct
9 Correct 20 ms 576 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 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 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 344 KB Output is correct
20 Correct 1 ms 356 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 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 1 ms 344 KB Output is correct
30 Correct 42 ms 616 KB Output is correct
31 Correct 48 ms 600 KB Output is correct
32 Correct 42 ms 608 KB Output is correct
33 Correct 43 ms 584 KB Output is correct
34 Correct 42 ms 608 KB Output is correct
35 Correct 46 ms 604 KB Output is correct
36 Correct 47 ms 600 KB Output is correct
37 Correct 45 ms 600 KB Output is correct
38 Correct 20 ms 596 KB Output is correct
39 Correct 55 ms 592 KB Output is correct
40 Correct 45 ms 612 KB Output is correct
41 Correct 45 ms 600 KB Output is correct
42 Correct 20 ms 600 KB Output is correct
43 Correct 42 ms 600 KB Output is correct
44 Correct 45 ms 592 KB Output is correct
45 Correct 44 ms 600 KB Output is correct