답안 #212373

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
212373 2020-03-22T19:35:15 Z M0REDA 카멜레온의 사랑 (JOI20_chameleon) C++14
100 / 100
138 ms 636 KB
#include <bits/stdc++.h>
#include "chameleon.h"
#define debug(x) cerr << #x << " = " << x << ", ";
#define ll long long
#define pb push_back
using namespace std;
#define FAST_IO                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

vector<vector<int>> v;
vector<int> graph;
vector<vector<int>> seq;
vector<int> cutoff(int l, int r, vector<int> v)
{
    vector<int> ret;
    for (int i = l; i <= r; i += 1)
    {
        ret.push_back(v[i]);
    }
    return ret;
}
int binarysearch(int l, int r, vector<int> v1, int x)
{
    r += 1;
    while (r - l > 1)
    {
        int m = (l + r) / 2;
        vector<int> q = cutoff(m, r - 1, v1);
        q.push_back(x);
        if (Query(q) == q.size())
        {
            r = m;
        }
        else
        {
            l = m;
        }
    }
    v[x].push_back(v1[l]);
    v[v1[l]].push_back(x);
    return l - 1;
}

void Solve(int N)
{
    v.resize(2 * N + 1);
    graph.resize(2 * N + 1, -1);
    vector<bool> done(2 * N + 1, true);
    seq.resize(4);
    for (int i = 1; i <= 2 * N; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            if (seq[j].size() == 0)
            {
                if (done[i])
                {
                    seq[j].pb(i);
                    done[i] = false;
                }
                continue;
            }
            bool asd = true;
            vector<int> p;
            p = seq[j];
            p.pb(i);
            int l = 0, r = p.size() - 2;
            vector<int> q = cutoff(l, r, p);
            q.pb(i);
            while (r >= l && Query(q) != q.size())
            {
                asd = false;
                r = binarysearch(l, r, p, i);
                q = cutoff(l, r, p);
                q.push_back(i);
            }
            if (done[i] && asd)
            {
                seq[j].pb(i);
                done[i] = false;
            }
        }
    }
    for (auto a : v)
    {
        for (auto b : a)
        {
            cerr << b << " ";
        }
        cerr << endl;
    }
    for (int i = 1; i <= 2 * N; i++)
    {
        if (v[i].size() == 1)
        {
            continue;
        }
        for (int j = 0; j < 3 && graph[i] == -1; j++)
        {
            for (int k = j + 1; k < 3; k++)
            {
                vector<int> p;
                p.pb(i);
                p.pb(v[i][j]);
                p.pb(v[i][k]);
                if (Query(p) == 1)
                {
                    graph[i] = v[i][3 - j - k];
                    break;
                }
            }
        }
    }
    for (int i = 1; i <= 2 * N; i++)
    {
        debug(i);
        cerr << endl;
        cerr << " tttttttttt " << endl;
        if (v[i].size() == 1)
        {
            debug(i);

            debug(v[i][0]);
            cerr << endl;
            cerr << "===================" << endl;
            if (i < v[i][0])
                Answer(i, v[i][0]);
            continue;
        }
        for (int j = 0; j < 3; j++)
        {
            debug(i);
            debug(v[i][j]);
            cerr << endl;
            if (v[i][j] == graph[i] || i == graph[v[i][j]])
            {
                continue;
            }
            cerr << "passed" << endl;
            cerr << "===================" << endl;

            if (i < v[i][j])
                Answer(i, v[i][j]);
            break;
        }
    }
}

Compilation message

chameleon.cpp: In function 'int binarysearch(int, int, std::vector<int>, int)':
chameleon.cpp:32:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (Query(q) == q.size())
             ~~~~~~~~~^~~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:72:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while (r >= l && Query(q) != q.size())
                              ~~~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 76 ms 504 KB Output is correct
4 Correct 70 ms 504 KB Output is correct
5 Correct 67 ms 504 KB Output is correct
6 Correct 67 ms 504 KB Output is correct
7 Correct 70 ms 504 KB Output is correct
8 Correct 82 ms 632 KB Output is correct
9 Correct 76 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
10 Correct 13 ms 404 KB Output is correct
11 Correct 9 ms 384 KB Output is correct
12 Correct 12 ms 384 KB Output is correct
13 Correct 11 ms 384 KB Output is correct
14 Correct 14 ms 384 KB Output is correct
15 Correct 9 ms 384 KB Output is correct
16 Correct 12 ms 384 KB Output is correct
17 Correct 12 ms 384 KB Output is correct
18 Correct 12 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 120 ms 480 KB Output is correct
4 Correct 126 ms 504 KB Output is correct
5 Correct 138 ms 564 KB Output is correct
6 Correct 127 ms 508 KB Output is correct
7 Correct 118 ms 456 KB Output is correct
8 Correct 121 ms 484 KB Output is correct
9 Correct 125 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 76 ms 504 KB Output is correct
4 Correct 70 ms 504 KB Output is correct
5 Correct 67 ms 504 KB Output is correct
6 Correct 67 ms 504 KB Output is correct
7 Correct 70 ms 504 KB Output is correct
8 Correct 82 ms 632 KB Output is correct
9 Correct 76 ms 504 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 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 6 ms 384 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
19 Correct 13 ms 404 KB Output is correct
20 Correct 9 ms 384 KB Output is correct
21 Correct 12 ms 384 KB Output is correct
22 Correct 11 ms 384 KB Output is correct
23 Correct 14 ms 384 KB Output is correct
24 Correct 9 ms 384 KB Output is correct
25 Correct 12 ms 384 KB Output is correct
26 Correct 12 ms 384 KB Output is correct
27 Correct 12 ms 256 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 6 ms 384 KB Output is correct
30 Correct 120 ms 480 KB Output is correct
31 Correct 126 ms 504 KB Output is correct
32 Correct 138 ms 564 KB Output is correct
33 Correct 127 ms 508 KB Output is correct
34 Correct 118 ms 456 KB Output is correct
35 Correct 121 ms 484 KB Output is correct
36 Correct 125 ms 636 KB Output is correct
37 Correct 122 ms 504 KB Output is correct
38 Correct 69 ms 504 KB Output is correct
39 Correct 120 ms 504 KB Output is correct
40 Correct 127 ms 632 KB Output is correct
41 Correct 123 ms 508 KB Output is correct
42 Correct 69 ms 504 KB Output is correct
43 Correct 124 ms 504 KB Output is correct
44 Correct 119 ms 632 KB Output is correct
45 Correct 120 ms 504 KB Output is correct