답안 #768616

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
768616 2023-06-28T10:01:53 Z raysh07 도서관 (JOI18_library) C++17
컴파일 오류
0 ms 0 KB
vector<vector<int>> adj;
vector<int> comp;

bool check(int i, int j, int n){
    if (i == j) return false;
    
    vector <int> m(n, 0);
    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) return false;
    
    int a1 = Query(m);
    m[i] = 0;
    int a2;
    if (cnt != 2)
    a2 = Query(m);
    else a2 = 1;
    
    return a2 >= a1;
}

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

void Solve(int n)
{
// 	vector<int> M(N);

// 	for(int i = 0; i < N; i++) {
// 		M[i] = 1;
// 	}

// 	int A = Query(M);

// 	vector<int> res(N);

// 	for(int i = 0; i < N; i++) {
// 		res[i] = i + 1;
// 	}

// 	Answer(res);

    adj.resize(n);
    
    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[i].push_back(l);
            adj[l].push_back(i);
        }
    }
    
    assert(ok == n - 1);
    
    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:1:1: error: 'vector' does not name a type
    1 | vector<vector<int>> adj;
      | ^~~~~~
library.cpp:2:1: error: 'vector' does not name a type
    2 | vector<int> comp;
      | ^~~~~~
library.cpp: In function 'bool check(int, int, int)':
library.cpp:7:5: error: 'vector' was not declared in this scope
    7 |     vector <int> m(n, 0);
      |     ^~~~~~
library.cpp:7:13: error: expected primary-expression before 'int'
    7 |     vector <int> m(n, 0);
      |             ^~~
library.cpp:9:9: error: 'm' was not declared in this scope
    9 |         m[k] = 1;
      |         ^
library.cpp:13:19: error: 'adj' was not declared in this scope
   13 |     for (auto x : adj[i]) m[x] = 0;
      |                   ^~~
library.cpp:13:27: error: 'm' was not declared in this scope
   13 |     for (auto x : adj[i]) m[x] = 0;
      |                           ^
library.cpp:15:40: error: 'm' was not declared in this scope
   15 |     for (int i = 0; i < n; i++) cnt += m[i];
      |                                        ^
library.cpp:19:20: error: 'm' was not declared in this scope
   19 |     int a1 = Query(m);
      |                    ^
library.cpp:19:14: error: 'Query' was not declared in this scope
   19 |     int a1 = Query(m);
      |              ^~~~~
library.cpp: In function 'void dfs(int, int)':
library.cpp:30:5: error: 'comp' was not declared in this scope
   30 |     comp.push_back(u + 1);
      |     ^~~~
library.cpp:31:18: error: 'adj' was not declared in this scope
   31 |     for (int v : adj[u]){
      |                  ^~~
library.cpp: In function 'void Solve(int)':
library.cpp:56:5: error: 'adj' was not declared in this scope
   56 |     adj.resize(n);
      |     ^~~
library.cpp:77:5: error: 'assert' was not declared in this scope
   77 |     assert(ok == n - 1);
      |     ^~~~~~
library.cpp:1:1: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
  +++ |+#include <cassert>
    1 | vector<vector<int>> adj;
library.cpp:87:12: error: 'comp' was not declared in this scope
   87 |     Answer(comp);
      |            ^~~~
library.cpp:87:5: error: 'Answer' was not declared in this scope
   87 |     Answer(comp);
      |     ^~~~~~