Submission #212623

# Submission time Handle Problem Language Result Execution time Memory
212623 2020-03-23T20:34:07 Z ereonzis Chameleon's Love (JOI20_chameleon) C++17
100 / 100
44 ms 436 KB
#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;


using LL = long long int;
using uLL = unsigned long long int;
using uint = unsigned int;
using ld = long double;

const int MAXN = 1007;

vector <int> group[MAXN];
vector <int> structure[4];
int ans[MAXN], beloved[MAXN], beloving[MAXN];
vector <vector <int> > indices = {{0, 1}, {0, 2}};
vector <int> not_present = {2, 1};


vector <int> sub_vector(int l, int r, vector <int> &w){
    if(l > r){
        vector <int> res;
        return res;
    }
    vector <int> res(r-l);
    for(int i = l; i < r; i++){
        res[i-l] = w[i];
    }
    return res;
}

int binarysearch(int l, int r, int id, int g){
    //cout << "G " << id << " " << g << " " << l << " " << r << '\n';
    while(l+1 < r){
        int mid = (l+r)>>1;
        //cout << l << " " << mid << " " << r << '\n';
        vector <int> temp = sub_vector(l+1, mid+1, structure[g]);
        temp.push_back(id);
        if(Query(temp) == int(temp.size())){
            l = mid;
        }
        else{
            r = mid;
        }
    }
    return r;
}

void update(int id){
    //cout << "ID " << id << '\n';
    bool czy = false;
    int licz = 0;
    for(int g = 0; g < 4; g++){
        vector <int> temp = structure[g];
        temp.push_back(id);
        if(licz == 3 || structure[g].empty() || Query(temp) == int(temp.size())){
            if(!czy){
                structure[g].push_back(id);
                //cout << "ADD " << g << " " << id << '\n';
                czy = true;
            }
        }
        else{
            int l = -1;
            int r = int(structure[g].size())-1;
            do{
                int x = binarysearch(l, r, id, g);
                group[structure[g][x]].push_back(id);
                group[id].push_back(structure[g][x]);
                //cout << "UP " << structure[g][x] << '\n';
                l = x;
                temp = sub_vector(l+1, r+1, structure[g]);
                temp.push_back(id);
                licz++;
                //cout << (licz < 3) << " " << (l < r) << '\n';
            }while(licz < 3 && l < r && Query(temp) < int(temp.size()));
        }
    }
    
}

void make_edge(int id){
    if(group[id].size() == 1){
        return;
    }
    /*cout << "GROUP " << id << '\n';
    for(auto x: group[id]){
        cout << x << " ";
    }
    cout << '\n';*/
    for(int i = 0; i < 2; i++){
        vector <int> temp = {id, group[id][indices[i][0]], group[id][indices[i][1]]};
        if(Query(temp) == 1){
            beloved[id] = group[id][not_present[i]];
            beloving[group[id][not_present[i]]] = id;
            return;
        }
    }
    beloved[id] = group[id][0];
    beloving[group[id][0]] = id;
    return;
}
void process_ans(int id){
    for(auto x: group[id]){
        if(x != beloved[id] && x != beloving[id]){
            ans[id] = x;
        }
    }
}


void Solve(int N){
    vector <int> tab(2*N);
    iota(tab.begin(), tab.end(), 1);
    srand(N);
    random_shuffle(tab.begin(), tab.end());
    for(auto x: tab){
        update(x);
    }
    for(int i = 1; i <= 2*N; i++){
        make_edge(i);
    }
    for(int i = 1; i <= 2*N; i++){
        process_ans(i);
    }
    /*for(int i = 1; i <= 2*N; i++){
        cout << ans[i] << '\n';
    }*/
    for(int i = 1; i <= 2*N; i++){
        if(i < ans[i]){
            Answer(i, ans[i]);
        }
    }
    
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 34 ms 384 KB Output is correct
4 Correct 23 ms 384 KB Output is correct
5 Correct 24 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 24 ms 436 KB Output is correct
9 Correct 26 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 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 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 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 4 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 6 ms 384 KB Output is correct
12 Correct 6 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 6 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 41 ms 384 KB Output is correct
4 Correct 41 ms 384 KB Output is correct
5 Correct 40 ms 384 KB Output is correct
6 Correct 44 ms 384 KB Output is correct
7 Correct 41 ms 384 KB Output is correct
8 Correct 42 ms 384 KB Output is correct
9 Correct 41 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 34 ms 384 KB Output is correct
4 Correct 23 ms 384 KB Output is correct
5 Correct 24 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 24 ms 436 KB Output is correct
9 Correct 26 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 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 4 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 6 ms 384 KB Output is correct
21 Correct 6 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 6 ms 384 KB Output is correct
25 Correct 5 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 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 41 ms 384 KB Output is correct
31 Correct 41 ms 384 KB Output is correct
32 Correct 40 ms 384 KB Output is correct
33 Correct 44 ms 384 KB Output is correct
34 Correct 41 ms 384 KB Output is correct
35 Correct 42 ms 384 KB Output is correct
36 Correct 41 ms 384 KB Output is correct
37 Correct 41 ms 384 KB Output is correct
38 Correct 24 ms 384 KB Output is correct
39 Correct 42 ms 384 KB Output is correct
40 Correct 41 ms 384 KB Output is correct
41 Correct 41 ms 384 KB Output is correct
42 Correct 24 ms 384 KB Output is correct
43 Correct 42 ms 384 KB Output is correct
44 Correct 40 ms 384 KB Output is correct
45 Correct 42 ms 384 KB Output is correct