답안 #218067

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
218067 2020-03-31T20:48:27 Z Akashi 카멜레온의 사랑 (JOI20_chameleon) C++14
100 / 100
64 ms 1748 KB
#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;

bool sex[1005];
vector <int> v[1005];

vector <int> Left, Right;
vector <int> cand[1005];

bool isCandidate(int x, int y, vector <int> v, int val){
    vector <int> q;
    if(val != -1) q.push_back(val);
    for(int i = x; i <= y ; ++i) q.push_back(v[i]);

    return Query(q) - q.size();
}

bool find_candidates(int i, vector <int> v){
    if(!v.empty()){
        while(isCandidate(0, v.size() - 1, v, i)){
            if(v.size() == 1){
                cand[i].push_back(v[0]);
                cand[v[0]].push_back(i);

                v.pop_back();
                break ;
            }

            int st = 1, dr = v.size();
            while(st <= dr){
                int mij = (st + dr) / 2;
                if(isCandidate(st - 1, mij - 1, v, i)) dr = mij - 1;
                else st = mij + 1;
            }

            cand[i].push_back(v[st - 1]);
            cand[v[st - 1]].push_back(i);

            swap(v[st - 1], v[v.size() - 1]);
            v.pop_back();

            if(v.empty() || cand[i].size() == 3) break ;
        }
    }
}

bool viz[1005];
void color(int nod){
    viz[nod] = 1;
    for(auto it : cand[nod]){
        if(viz[it]) continue ;
        sex[it] = 1 - sex[nod];
        color(it);
    }
}

bool match[1005][1005];
bool found[1005];

void Solve(int n){
    for(int i = 2; i <= 2 * n ; ++i){
        for(int j = 1; j < i ; ++j) viz[j] = 0;

        sex[i - 1] = 0;
        color(i - 1);

        ///we find all the chameleons on the left
        Left.clear();
        for(int j = 1; j < i ; ++j)
            if(sex[j] == 0 && cand[j].size() < 3) Left.push_back(j);

        find_candidates(i, Left);

        if(cand[i].size() == 3) continue ;

        ///we find all the chameleons on the right
        Right.clear();
        for(int j = 1; j < i ; ++j)
            if(sex[j] == 1 && cand[j].size() < 3) Right.push_back(j);

        find_candidates(i, Right);
    }

    for(int i = 1; i <= 2 * n ; ++i){
        if(found[i]) continue ;
        if(cand[i].size() == 1){
            found[i] = found[cand[i][0]] = true;
            Answer(i, cand[i][0]);
            continue ;
        }

        vector <int> v;
        bool ok = false;
        for(auto x : cand[i]){
            for(auto y : cand[i]){
                if(x >= y) continue ;
                v.clear();
                v.push_back(x);
                v.push_back(y);
                v.push_back(i);
                if(Query(v) == 1){
                    match[i][x] = 1;
                    match[i][y] = 1;
                    ok = true;
                    break ;
                }
            }
            if(ok) break ;
        }
    }

    for(int i = 1; i <= 2 * n ; ++i){
        if(found[i]) continue ;
        for(int j = 1; j <= 2 * n ; ++j){
            if(found[j]) continue ;
            if(match[i][j] && match[j][i]){
                found[i] = found[j] = true;
                Answer(i, j);
            }
        }
    }
}

Compilation message

chameleon.cpp: In function 'bool find_candidates(int, std::vector<int>)':
chameleon.cpp:46:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 33 ms 384 KB Output is correct
4 Correct 33 ms 512 KB Output is correct
5 Correct 34 ms 384 KB Output is correct
6 Correct 33 ms 512 KB Output is correct
7 Correct 33 ms 384 KB Output is correct
8 Correct 34 ms 384 KB Output is correct
9 Correct 33 ms 504 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 4 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 4 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 4 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 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 54 ms 1400 KB Output is correct
4 Correct 53 ms 1400 KB Output is correct
5 Correct 52 ms 1476 KB Output is correct
6 Correct 53 ms 1400 KB Output is correct
7 Correct 53 ms 1400 KB Output is correct
8 Correct 52 ms 1400 KB Output is correct
9 Correct 54 ms 1400 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 33 ms 384 KB Output is correct
4 Correct 33 ms 512 KB Output is correct
5 Correct 34 ms 384 KB Output is correct
6 Correct 33 ms 512 KB Output is correct
7 Correct 33 ms 384 KB Output is correct
8 Correct 34 ms 384 KB Output is correct
9 Correct 33 ms 504 KB Output is correct
10 Correct 5 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 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 4 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 512 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 5 ms 512 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 512 KB Output is correct
26 Correct 5 ms 512 KB Output is correct
27 Correct 5 ms 512 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 54 ms 1400 KB Output is correct
31 Correct 53 ms 1400 KB Output is correct
32 Correct 52 ms 1476 KB Output is correct
33 Correct 53 ms 1400 KB Output is correct
34 Correct 53 ms 1400 KB Output is correct
35 Correct 52 ms 1400 KB Output is correct
36 Correct 54 ms 1400 KB Output is correct
37 Correct 53 ms 1400 KB Output is correct
38 Correct 33 ms 476 KB Output is correct
39 Correct 52 ms 1360 KB Output is correct
40 Correct 53 ms 1400 KB Output is correct
41 Correct 64 ms 1748 KB Output is correct
42 Correct 34 ms 384 KB Output is correct
43 Correct 53 ms 1400 KB Output is correct
44 Correct 54 ms 1388 KB Output is correct
45 Correct 53 ms 1400 KB Output is correct