Submission #679139

#TimeUsernameProblemLanguageResultExecution timeMemory
679139Ronin13Library (JOI18_library)C++14
0 / 100
62 ms296 KiB
#include <cstdio>
#include <vector>
#include "library.h"
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

vector <int> vec;
vector <int> def;
int n;
int get(int x){
    int l = -1, r = vec.size() - 1;
    while(l + 1 < r){
        def.assign(n, 0);
        int mid = (l + r) / 2;
        vector <int> qv;
        for(int j = 0; j <= mid; j++){
            qv.pb(vec[j]);
        }
        for(int to : qv) def[to - 1] = 1;
        int u = Query(def);
        def[x - 1] = 1;
        int v = Query(def);
        if(u == v) r = mid;
        else l = mid;

    }
    return vec[r];
}

void Solve(int N)
{
	n = N;

	for(int i = 1; i <= n; i++)
        vec.pb(i), def.pb(0);
    vector <int> ans;
    for(int i = 1; i <= n; i++){
        vector <int> qv;
        for(int j = 0; j < i - 1; j++) qv.pb(vec[j]);
        for(int j = i; j < vec.size(); j++) qv.pb(vec[j]);
        for(int to : qv)
            def[to - 1] = 1;
        int l = Query(def);
        def.assign(n, 0);
        if(l <= 1){
            ans.pb(i);
            break;
        }
    }
    //cout << ans.back();
    for(int j = 1; j < n; j++){
        for(int x = 0; x < vec.size(); x++){
            if(vec[x] == ans.back()){
                int pos = x;
                while(pos < vec.size() - 1) swap(vec[pos], vec[pos + 1]), pos++;
                vec.pop_back();
                break;
            }
        }
        ans.pb(get(ans.back()));
    }
    Answer(ans);
}

Compilation message (stderr)

library.cpp: In function 'void Solve(int)':
library.cpp:41:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         for(int j = i; j < vec.size(); j++) qv.pb(vec[j]);
      |                        ~~^~~~~~~~~~~~
library.cpp:53:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for(int x = 0; x < vec.size(); x++){
      |                        ~~^~~~~~~~~~~~
library.cpp:56:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |                 while(pos < vec.size() - 1) swap(vec[pos], vec[pos + 1]), pos++;
      |                       ~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...