Submission #768654

# Submission time Handle Problem Language Result Execution time Memory
768654 2023-06-28T10:35:34 Z raysh07 Library (JOI18_library) C++17
0 / 100
220 ms 2672 KB
#include <bits/stdc++.h>
#include "library.h"
using namespace std;
vector<vector<int>> adj;
vector<int> comp;
vector<bool> vis;
vector<int> m;
vector <int> perm;
int q = 0;

void init(int n){
    for (int i = 0; i < n; i++) m[i] = 0;
}

int go(vector <int> m){
    q++;
    if (q > 20000) exit(0);
    
    return Query(m);
}

bool check(int i, int j, int n){
    if (i == j) return false;
    
    for (int k = i; k <= j; k++){
        m[perm[k]] = 1;
    }
    int cnt = 0;
    
    for (auto x : adj[i]) m[perm[x]] = 0;
    
    for (int i = 0; i < n; i++) cnt += m[i];
    
    if (cnt == 1) {
        init(n);
        return false;
    }
    
    int a1 = go(m);
    m[perm[i]] = 0;
    int a2;
    if (cnt != 2)
    a2 = go(m);
    else a2 = 1;
    
    init(n);
    return a2 >= a1;
}

void dfs(int u, int par = -1){
    comp.push_back(u + 1);
    vis[u] = true;
    for (int v : adj[u]){
        if (v != par){
            assert(!vis[v]);
            dfs(v, u);
        }
    }
}

void Solve(int n)
{
    if (n == 1){
        Answer({1});
        return;
    }
    if (n == 2){
        Answer({1, 2});
        return;
    }
    
    for (int i = 0; i < n; i++) perm.push_back(i);
    random_shuffle(perm.begin(), perm.end());
    
    m.resize(n, 0);
    adj.resize(1e5 + 69);
    vis.resize(1e5 + 69, false);
    
    int ok = 0;

    for (int i = 0; i < n; i++){
        while (adj[i].size() < 2 && check(i, n - 1, n)){
            int l = i + 1, r = n - 1;
            
            while (l != r){
                int m = (l + r)/2;
                
                if (check(i, m, n)) r = m;
                else l = m + 1;
            }
            
            ok++;
            adj[perm[i]].push_back(perm[l]);
            adj[perm[l]].push_back(perm[i]);
        }
    }
    
    for (int i = 0; i < n; i++){
        if (adj[i].size() == 1){
            dfs(i);
            break;
        }
    }
    assert(comp.size() == n);
    
    Answer(comp);
}

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from library.cpp:1:
library.cpp: In function 'void Solve(int)':
library.cpp:104:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  104 |     assert(comp.size() == n);
      |            ~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 220 ms 2672 KB Unexpected end of file - token expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 220 ms 2672 KB Unexpected end of file - token expected
2 Halted 0 ms 0 KB -