Submission #269388

# Submission time Handle Problem Language Result Execution time Memory
269388 2020-08-17T06:49:04 Z 반딧불(#5114) Chameleon's Love (JOI20_chameleon) C++17
100 / 100
40 ms 632 KB
#include <bits/stdc++.h>
#include "chameleon.h"

using namespace std;

int n;
vector<int> link[1002];
int opp[1002];

vector<int> range(int l, int r){
    vector<int> ret;
    for(int i=l; i<=r; i++) ret.push_back(i);
    return ret;
}

int group[1002];
int fast[1002];
vector<int> groupVec[3];

void dfs(int x, int g){
    group[x] = g;
    if(link[x].size() <= 2) groupVec[g].push_back(x);
    for(auto &y: link[x]){
        if(!group[y]) dfs(y, 3-g);
    }
}

void Solve(int N){
    n = N;
    for(int i=2; i<=2*n; i++){
        memset(group, 0, sizeof(group));
        groupVec[1].clear(), groupVec[2].clear();
        for(int j=1; j<i; j++){
            if(!group[j]) dfs(j, (groupVec[1].size() < groupVec[2].size()) ? 2 : 1);
        }

        int cnt=0;
        for(int session = 1; session <= 2; session++){
            int l = 0, r = (int)groupVec[session].size()-1, nxt = (int)groupVec[session].size();
            while(1){
                if(cnt >= 3) break;
                vector<int> queryVecTmp (groupVec[session].begin()+l, groupVec[session].end());
                queryVecTmp.push_back(i);
                if(Query(queryVecTmp) == (int)queryVecTmp.size()) break;

                while(l<=r){
                    int m = (l+r+1)>>1;
                    vector<int> queryVec (groupVec[session].begin()+l, groupVec[session].begin()+m+1);
                    queryVec.push_back(i);
                    int qq = Query(queryVec);

                    if(qq != (int)queryVec.size()) nxt = m, r = m-1;
                    else l = m+1;
                }

                if(nxt == (int)groupVec[session].size()) break;
                int tmp = groupVec[session][nxt];
//                printf("%d - %d\n", i, tmp);
                link[i].push_back(tmp), link[tmp].push_back(i);
                l = nxt+1, r = (int)groupVec[session].size()-1, nxt = r+1;
                cnt++;
            }
        }
    }

    memset(group, 0, sizeof(group));
    groupVec[1].clear(), groupVec[2].clear();

    for(int i=1; i<=2*n; i++){
        if(!group[i]){
            dfs(i, 1);
        }
    }
    for(int i=1; i<=2*n; i++){
        if((int)link[i].size() == 1){
            opp[i] = link[i][0];
            fast[i] = 1;
        }
    }

    for(int i=1; i<=2*n; i++){
        if((int)link[i].size() == 1){
            continue;
        }

        int g1 = link[i][0], g2 = link[i][1], g3 = link[i][2];
        opp[i] += g1 + g2 + g3;
        if(Query({i, g2, g3}) == 1){
            opp[i] -= g1;
            if(!fast[g1]) opp[g1] -= i;
        }
        else if(Query({i, g1, g3}) == 1){
            opp[i] -= g2;
            if(!fast[g2]) opp[g2] -= i;
        }
        else{
            opp[i] -= g3;
            if(!fast[g3]) opp[g3] -= i;
        }
    }

    for(int i=1; i<=2*n; i++){
        if(i < opp[i]) Answer(i, opp[i]);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 24 ms 384 KB Output is correct
4 Correct 34 ms 384 KB Output is correct
5 Correct 23 ms 384 KB Output is correct
6 Correct 23 ms 384 KB Output is correct
7 Correct 24 ms 384 KB Output is correct
8 Correct 23 ms 384 KB Output is correct
9 Correct 24 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 39 ms 384 KB Output is correct
4 Correct 38 ms 384 KB Output is correct
5 Correct 38 ms 384 KB Output is correct
6 Correct 40 ms 384 KB Output is correct
7 Correct 38 ms 384 KB Output is correct
8 Correct 39 ms 384 KB Output is correct
9 Correct 38 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 24 ms 384 KB Output is correct
4 Correct 34 ms 384 KB Output is correct
5 Correct 23 ms 384 KB Output is correct
6 Correct 23 ms 384 KB Output is correct
7 Correct 24 ms 384 KB Output is correct
8 Correct 23 ms 384 KB Output is correct
9 Correct 24 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 39 ms 384 KB Output is correct
31 Correct 38 ms 384 KB Output is correct
32 Correct 38 ms 384 KB Output is correct
33 Correct 40 ms 384 KB Output is correct
34 Correct 38 ms 384 KB Output is correct
35 Correct 39 ms 384 KB Output is correct
36 Correct 38 ms 384 KB Output is correct
37 Correct 36 ms 384 KB Output is correct
38 Correct 24 ms 384 KB Output is correct
39 Correct 37 ms 384 KB Output is correct
40 Correct 40 ms 632 KB Output is correct
41 Correct 36 ms 384 KB Output is correct
42 Correct 25 ms 384 KB Output is correct
43 Correct 39 ms 384 KB Output is correct
44 Correct 38 ms 512 KB Output is correct
45 Correct 37 ms 384 KB Output is correct