Submission #215882

# Submission time Handle Problem Language Result Execution time Memory
215882 2020-03-26T12:06:03 Z BThero Chameleon's Love (JOI20_chameleon) C++17
40 / 100
130 ms 612 KB
#define DBG 1
// chrono::system_clock::now().time_since_epoch().count()
#include<bits/stdc++.h>
#include "chameleon.h"
//#include<ext/pb_ds/tree_policy.hpp>
//#include<ext/pb_ds/assoc_container.hpp>

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define debug(x) if (DBG) cerr << #x << " = " << x << endl;

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef pair<int, int> pii;

//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

namespace {
    const int MAXN = 1005;
    vector<int> adj[MAXN];
    int partner[MAXN], loves[MAXN], n;  
    int col[MAXN];  
    
    void addEdge(int u, int v, bool check = 0) {
        if (check && Query({u, v}) != 1) {
            return;
        }
        
        adj[u].pb(v);
        adj[v].pb(u);
    }
    
    void dfs(int v) {
        for (int to : adj[v]) {
            if (col[to] == -1) {
                col[to] = 1 - col[v];
                dfs(to);
            }
            else if (col[to] == col[v]) {
                assert(0);
            }
        }
    }
}

void Solve(int _n) {
    n = _n;
    
    for (int i = 1; i <= 2 * n; ++i) {
        for (int j = 1; j < i; ++j) {
            col[j] = -1;
        }
        
        vector<vector<int>> vec(2);
        
        for (int j = 1; j < i; ++j) {
            if (col[j] == -1) {
                col[j] = 0;
                dfs(j);
            }
            
            vec[col[j]].pb(j);
        }
    
        for (vector<int> v : vec) {
            while (1) {
                int l = 0;
                int r = (int)v.size() - 1;
                int p = -1;
                
                while (l <= r) {
                    int mid = (l + r) >> 1;
                    vector<int> tmp;
                    tmp.pb(i);
                    
                    for (int j = 0; j <= mid; ++j) {
                        tmp.pb(v[j]);
                    }
                    
                    if (Query(tmp) == tmp.size()) {
                        l = mid + 1;
                    }
                    else {
                        r = mid - 1;
                        p = mid;
                    }
                }
                
                if (p != -1) {
                    addEdge(i, v[p], 1);
                    v.erase(v.begin() + p);
                }
                else {
                    break;
                }
            }
        }
    }
    
    for (int i = 1; i <= 2 * n; ++i) {
        assert(adj[i].size() == 1 || adj[i].size() == 3);
        
        if (adj[i].size() == 1) {
            partner[i] = adj[i][0];
            continue;
        }
        
        while (Query({i, adj[i][0], adj[i][1]}) != 1) {
            rotate(adj[i].begin(), adj[i].begin() + 1, adj[i].end());
        }
        
        loves[i] = adj[i][2];
    }
    
    for (int i = 1; i <= 2 * n; ++i) {
        if (loves[adj[i][0]] == i) {
            partner[i] = adj[i][1];
        }
        else {
            partner[i] = adj[i][0];
        }
    }
    
    for (int i = 1; i <= 2 * n; ++i) {
        if (i < partner[i]) {
            Answer(i, partner[i]);
        }
    }
}

Compilation message

chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:86:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     if (Query(tmp) == tmp.size()) {
                         ~~~~~~~~~~~^~~~~~~~~~~~~
# 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 116 ms 612 KB Output is correct
4 Correct 114 ms 508 KB Output is correct
5 Correct 111 ms 384 KB Output is correct
6 Incorrect 130 ms 384 KB Wrong Answer [3]
7 Halted 0 ms 0 KB -
# 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 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 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 6 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 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 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 6 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 6 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 7 ms 384 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 7 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 Incorrect 108 ms 416 KB Wrong Answer [3]
4 Halted 0 ms 0 KB -
# 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 116 ms 612 KB Output is correct
4 Correct 114 ms 508 KB Output is correct
5 Correct 111 ms 384 KB Output is correct
6 Incorrect 130 ms 384 KB Wrong Answer [3]
7 Halted 0 ms 0 KB -