답안 #1081347

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1081347 2024-08-30T00:36:38 Z kustizus 도서관 (JOI18_library) C++17
0 / 100
13 ms 344 KB
// #pragma GCC optimize("O3","unroll-loops")
#include <bits/stdc++.h>
#include "library.h"
using namespace std;

// #define 
#define all(v) v.begin(), v.end()
#define fi first
#define se second

mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
// declare
const int N=1e3;
bool vs[N+5];
vector <int> ans;
vector <int> g[N + 5];
void dfs(int i){
    ans.push_back(i);
    vs[i] = true;
    for (int j : g[i])
        if (!vs[j])
            dfs(j);
}
void Solve(int n)
{
    int now = 1;
    for (int i = 1; i < n; i++){
        vector <int> m;
        for (int j = 1; j <= n; ++j)
            if (!vs[j] && now != j)
                m.push_back(j);
        int l = 1, r = m.size(), res = -1;
        while (l < r)
        {
            int md = (l + r) / 2;
            vector <int> ch(n);
            for (int k = l; k <= md; ++k)
                ch[m[k - 1] - 1]=1;
            int c1 = Query(ch);
            ch[now - 1] = 1;
            int c2 = Query(ch);
            if (c1 >= c2) res = md, r = md - 1;
            else l = md + 1;
        }
        if (res == -1)
        {
            vs[now] = 1;
            now = 1;
        }
        else 
        {
            vs[now] = 1;
            res = m[res - 1];
            g[now].push_back(res);
            g[res].push_back(now);
            now = res;
        }
    }
    int idx, mn = 2000;
    for (int i = 1; i <= n; ++i)
        if (g[i].size() <= mn)
        {
            mn = g[i].size();
            idx = i;
        }
    for (int i = 1; i <= n; ++i) vs[i] = false; 
    dfs(idx);
    Answer(ans);
}

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:61:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   61 |         if (g[i].size() <= mn)
      |             ~~~~~~~~~~~~^~~~~
library.cpp:67:8: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   67 |     dfs(idx);
      |     ~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 344 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 344 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -