Submission #768660

# Submission time Handle Problem Language Result Execution time Memory
768660 2023-06-28T10:43:11 Z raysh07 Library (JOI18_library) C++17
Compilation error
0 ms 0 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> deg;
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[k] = 1;
    }
    int cnt = 0;
    
    for (auto x : adj[i]) m[x] = 0;
    
    for (int i = 0; i < n; i++) cnt += m[i];
    
    if (cnt == 1) {
        init(n);
        return false;
    }
    
    int a1 = go(m);
    m[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;
    }
    
    m.resize(n, 0);
    deg.resize(n, 0);
    adj.resize(1e5 + 69);
    vis.resize(1e5 + 69, false);
    
    int ok = 0;
    
    vector <int> m(n, 1);
    vector <int> ok;
    ok.push_back(1);
    for (int i = 0; i < n; i++){
        m[i] = 0;
        if (i == n - 1){
            ok.push_back(0);
        } else if (i == n - 2){
            ok.push_back(1);
        } else {
            ok.push_back(Query(m));
        }
    }
    
    for (int i = 0; i < n; i++){
        deg[i] = ok[i + 1] - ok[i] + 1;
    }
 
    for (int i = 0; i < n; i++){
        int tm = 0;
        while (tm < deg[i]){
            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[i].push_back(l);
            adj[l].push_back(i);
            tm++;
        }
    }
    
    for (int i = 0; i < n; i++){
        if (adj[i].size() == 1){
            dfs(i);
            break;
        }
    }
    assert(comp.size() == n);
    
    Answer(comp);
}

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:80:18: error: conflicting declaration 'std::vector<int> ok'
   80 |     vector <int> ok;
      |                  ^~
library.cpp:77:9: note: previous declaration as 'int ok'
   77 |     int ok = 0;
      |         ^~
library.cpp:81:8: error: request for member 'push_back' in 'ok', which is of non-class type 'int'
   81 |     ok.push_back(1);
      |        ^~~~~~~~~
library.cpp:85:16: error: request for member 'push_back' in 'ok', which is of non-class type 'int'
   85 |             ok.push_back(0);
      |                ^~~~~~~~~
library.cpp:87:16: error: request for member 'push_back' in 'ok', which is of non-class type 'int'
   87 |             ok.push_back(1);
      |                ^~~~~~~~~
library.cpp:89:16: error: request for member 'push_back' in 'ok', which is of non-class type 'int'
   89 |             ok.push_back(Query(m));
      |                ^~~~~~~~~
library.cpp:94:20: error: invalid types 'int[int]' for array subscript
   94 |         deg[i] = ok[i + 1] - ok[i] + 1;
      |                    ^
library.cpp:94:32: error: invalid types 'int[int]' for array subscript
   94 |         deg[i] = ok[i + 1] - ok[i] + 1;
      |                                ^
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:122:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  122 |     assert(comp.size() == n);
      |            ~~~~~~~~~~~~^~~~