Submission #768609

# Submission time Handle Problem Language Result Execution time Memory
768609 2023-06-28T09:58:44 Z raysh07 Library (JOI18_library) C++17
0 / 100
45 ms 336 KB
#include <bits/stdc++.h>
#include "library.h"
using namespace std;

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);

    for (int i = 0; i < n; i++){
        while (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;
            }
            
            adj[i].push_back(l);
            adj[l].push_back(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:84:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   84 |     assert(comp.size() == n);
      |            ~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 30 ms 208 KB # of queries: 3397
2 Correct 38 ms 304 KB # of queries: 3372
3 Correct 41 ms 300 KB # of queries: 3575
4 Correct 39 ms 292 KB # of queries: 3552
5 Correct 41 ms 288 KB # of queries: 3563
6 Correct 35 ms 296 KB # of queries: 3579
7 Correct 33 ms 304 KB # of queries: 3571
8 Correct 45 ms 300 KB # of queries: 3410
9 Correct 38 ms 304 KB # of queries: 3531
10 Correct 18 ms 304 KB # of queries: 2125
11 Runtime error 1 ms 336 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 208 KB # of queries: 3397
2 Correct 38 ms 304 KB # of queries: 3372
3 Correct 41 ms 300 KB # of queries: 3575
4 Correct 39 ms 292 KB # of queries: 3552
5 Correct 41 ms 288 KB # of queries: 3563
6 Correct 35 ms 296 KB # of queries: 3579
7 Correct 33 ms 304 KB # of queries: 3571
8 Correct 45 ms 300 KB # of queries: 3410
9 Correct 38 ms 304 KB # of queries: 3531
10 Correct 18 ms 304 KB # of queries: 2125
11 Runtime error 1 ms 336 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -