Submission #230986

# Submission time Handle Problem Language Result Execution time Memory
230986 2020-05-12T09:10:13 Z PeppaPig Chameleon's Love (JOI20_chameleon) C++14
100 / 100
68 ms 532 KB
#include "chameleon.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 1e3+5;

int same[N], nex[N], pre[N];
vector<int> g[N];

bool find_edge(vector<int> v, int x) {
    v.emplace_back(x);
    return Query(v) < v.size();
}

void Solve(int n) {
    n *= 2;
    for(int i = 1; i <= n; i++) {
        vector<int> col(n + 1), vec[3];
        function<void(int, int)> dfs = [&](int u, int c) {
            col[u] = c;
            for(int v : g[u]) if(!col[v]) dfs(v, c ^ 3);
        };
        for(int j = 1; j < i; j++) {
            if(!col[j]) dfs(j, 1);
            vec[col[j]].emplace_back(j);
        }
        for(int j = 1; j <= 2; j++) {
            vector<int> now = vec[j];
            while(find_edge(now, i)) {
                int l = 0, r = now.size() - 1;
                while(l < r) {
                    int mid = (l + r) >> 1;
                    vector<int> v(now.begin(), now.begin() + mid + 1);
                    if(find_edge(v, i)) r = mid;
                    else l = mid + 1;
                }
                g[now[r]].emplace_back(i), g[i].emplace_back(now[r]);
                now = vector<int>(now.begin() + r + 1, now.end());
            }
        }
    }

    for(int i = 1; i <= n; i++) {
        if(g[i].size() == 1) same[i] = g[i][0];
        else {
            while(Query({i, g[i][0], g[i][1]}) != 1) {
                int x = g[i][0];
                g[i].erase(g[i].begin()), g[i].emplace_back(x);
            }
            nex[i] = g[i][2], pre[g[i][2]] = i;
        }
    }
    for(int i = 1; i <= n; i++) {
        if(!same[i]) same[i] = g[i][0] + g[i][1] + g[i][2] - nex[i] - pre[i];
        if(i < same[i]) Answer(i, same[i]);
    }
}

Compilation message

chameleon.cpp: In function 'bool find_edge(std::vector<int>, int)':
chameleon.cpp:13:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     return Query(v) < v.size();
            ~~~~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 42 ms 384 KB Output is correct
4 Correct 42 ms 384 KB Output is correct
5 Correct 43 ms 532 KB Output is correct
6 Correct 43 ms 384 KB Output is correct
7 Correct 43 ms 512 KB Output is correct
8 Correct 43 ms 384 KB Output is correct
9 Correct 43 ms 384 KB Output is correct
# Verdict Execution time Memory 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
# Verdict Execution time Memory 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 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 6 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 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 66 ms 504 KB Output is correct
4 Correct 66 ms 504 KB Output is correct
5 Correct 66 ms 384 KB Output is correct
6 Correct 68 ms 504 KB Output is correct
7 Correct 66 ms 504 KB Output is correct
8 Correct 65 ms 504 KB Output is correct
9 Correct 66 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 42 ms 384 KB Output is correct
4 Correct 42 ms 384 KB Output is correct
5 Correct 43 ms 532 KB Output is correct
6 Correct 43 ms 384 KB Output is correct
7 Correct 43 ms 512 KB Output is correct
8 Correct 43 ms 384 KB Output is correct
9 Correct 43 ms 384 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 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 6 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 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 4 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 66 ms 504 KB Output is correct
31 Correct 66 ms 504 KB Output is correct
32 Correct 66 ms 384 KB Output is correct
33 Correct 68 ms 504 KB Output is correct
34 Correct 66 ms 504 KB Output is correct
35 Correct 65 ms 504 KB Output is correct
36 Correct 66 ms 504 KB Output is correct
37 Correct 64 ms 504 KB Output is correct
38 Correct 43 ms 384 KB Output is correct
39 Correct 64 ms 504 KB Output is correct
40 Correct 65 ms 452 KB Output is correct
41 Correct 64 ms 504 KB Output is correct
42 Correct 43 ms 436 KB Output is correct
43 Correct 65 ms 504 KB Output is correct
44 Correct 64 ms 496 KB Output is correct
45 Correct 64 ms 504 KB Output is correct