답안 #1068893

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1068893 2024-08-21T12:51:30 Z _8_8_ 카멜레온의 사랑 (JOI20_chameleon) C++17
64 / 100
43 ms 888 KB
#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
    
const int N = 5e3 + 12;
vector<int> g[N];
int n;
void make(vector<int> &l,vector<int> &r,int i) {
    l.clear();
    r.clear();
    vector<int> d(N,0);
    vector<int> x,y;
    function<void(int)>dfs = [&](int v) {
        if(d[v] & 1) {
            x.push_back(v);
        } else {
            y.push_back(v);
        }
        for(int to:g[v]) {
            if(!d[to]) {
                d[to] = d[v] + 1;
                dfs(to);
            }
        }
    };
    for(int j = 1;j < i;j++) {
        if(!d[j]) {
            d[j] = 1;
            x.clear();
            y.clear();
            dfs(j);
            if((int)x.size() < (int)y.size()) {
                x.swap(y);
            }
            for(int j:x ) {
                l.push_back(j);
            }
            for(int j:y ) {
                r.push_back(j);
            }
        }
    }
}
bool vis[N];
int to[N],fr[N];
set<int> st[N];
void Solve(int n_) {
    n = n_;
    vector<int> l,r;
    for(int i = 2;i <= n + n;i++) {
        make(l,r,i);
        auto ed = [&](vector<int> &x) -> void{
            int it = 0,m = (int)x.size();
            while(it < m) {
                if((int)g[i].size() == 3) break;
                int l = it - 1,r = m;
                while(r - l > 1) {
                    int mid = (l + r) >> 1;
                    vector<int> t(1,i);
                    for(int j = it; j <= mid; ++j) {
                        t.push_back(x[j]);
                    }
                    if(Query(t) != (int)t.size()) {
                        r = mid; 
                    } else {
                        l = mid;
                    }
                }
                if(r != m) {
                    g[i].push_back(x[r]);
                    g[x[r]].push_back(i);
                }
                if((int)g[i].size() == 3) break;
                it = r + 1;
            }
        };
        ed(l);
        ed(r);
    }
    for(int i = 1;i <= n + n;i++) {
        if(vis[i]) continue;
        if(g[i].size() == 1) {
            Answer(i,g[i][0]);
            vis[i] = vis[g[i][0]] = 1;
        }
    }
    for(int i = 1;i <= n + n;i++) {
        if(vis[i]) continue;
        for(int j:g[i]) {
            if(vis[j]) continue;
            st[i].insert(j);
        }
    }
    for(int i = 1;i <= n + n;i++) {
        if(vis[i]) continue;
        if((int)st[i].size() == 1) continue;
        if((int)g[i].size() >= 2 &&Query({i,g[i][0],g[i][1]}) == 1) {
            st[i].erase(g[i][2]);
            st[g[i][2]].erase(i);
        } else if(g[i].size() >= 3 && Query({i,g[i][2],g[i][1]}) == 1) {
            st[i].erase(g[i][0]);
            st[g[i][0]].erase(i);
        } else if(g[i].size() >= 3 && Query({i,g[i][0],g[i][2]}) == 1){
            st[i].erase(g[i][1]);
            st[g[i][1]].erase(i);
        }
    }
    for(int i = 1;i <= n + n;i++) {
        if(vis[i] || st[i].empty()) continue;
        int t = (*st[i].begin());
        Answer(i,t);
        vis[i] = vis[t] = 1;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 856 KB Output is correct
3 Correct 38 ms 848 KB Output is correct
4 Correct 38 ms 856 KB Output is correct
5 Correct 38 ms 856 KB Output is correct
6 Correct 38 ms 856 KB Output is correct
7 Correct 43 ms 836 KB Output is correct
8 Correct 38 ms 848 KB Output is correct
9 Correct 39 ms 848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 612 KB Output is correct
13 Correct 1 ms 848 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 856 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 784 KB Output is correct
3 Correct 38 ms 856 KB Output is correct
4 Correct 38 ms 888 KB Output is correct
5 Correct 37 ms 856 KB Output is correct
6 Correct 37 ms 852 KB Output is correct
7 Correct 39 ms 856 KB Output is correct
8 Correct 43 ms 856 KB Output is correct
9 Correct 37 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 856 KB Output is correct
3 Correct 38 ms 848 KB Output is correct
4 Correct 38 ms 856 KB Output is correct
5 Correct 38 ms 856 KB Output is correct
6 Correct 38 ms 856 KB Output is correct
7 Correct 43 ms 836 KB Output is correct
8 Correct 38 ms 848 KB Output is correct
9 Correct 39 ms 848 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 0 ms 600 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 612 KB Output is correct
22 Correct 1 ms 848 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 856 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 856 KB Output is correct
28 Correct 0 ms 600 KB Output is correct
29 Correct 0 ms 784 KB Output is correct
30 Correct 38 ms 856 KB Output is correct
31 Correct 38 ms 888 KB Output is correct
32 Correct 37 ms 856 KB Output is correct
33 Correct 37 ms 852 KB Output is correct
34 Correct 39 ms 856 KB Output is correct
35 Correct 43 ms 856 KB Output is correct
36 Correct 37 ms 888 KB Output is correct
37 Incorrect 39 ms 856 KB Wrong Answer [3]
38 Halted 0 ms 0 KB -