답안 #1018000

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1018000 2024-07-09T12:29:43 Z davit_tsibadze 도서관 (JOI18_library) C++17
0 / 100
2 ms 344 KB
#include "library.h"
#include <bits/stdc++.h>
using namespace std;

#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
 
const ll inf = 1e18;
// #define int long long
vector <int> ans, m, a;
bool isgood(int mid){
    for (int i = 0; i < m.size(); i++)
        m[i] = 0;
    for (int i = 0; i <= mid; i++)
        m[a[i] - 1] = 1;
    int x = Query(m);
    m[ans.back() - 1] = 1;
    int y = Query(m);
    return (x == y);
}
void Solve(int N){
    int d;
    while(m.size() < N)m.pb(1);
    for (int i = 1; i <= N; i++){
        m[i - 1] = 0;
        if (Query(m) == 1){d = i; break;}
        m[i] = 1;
    }
    ans.pb(d);
    for (int i = 1; i <= N; i++) if (i != d)a.pb(i);
    while(a.size()){
        int l = 0, r = a.size() - 1, mid, answ;
        while(l <= r){
            mid = (l + r) / 2;
            if (isgood(mid)) {
                answ = mid;
                r = mid - 1;
            }
            else l = mid + 1;
        }
        swap(a[answ], a[a.size() - 1]);
        ans.pb(a.back()); a.pop_back();
    }
    Answer(ans);
}

Compilation message

library.cpp: In function 'bool isgood(int)':
library.cpp:16:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for (int i = 0; i < m.size(); i++)
      |                     ~~^~~~~~~~~~
library.cpp: In function 'void Solve(int)':
library.cpp:27:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |     while(m.size() < N)m.pb(1);
      |           ~~~~~~~~~^~~
library.cpp:45:20: warning: 'answ' may be used uninitialized in this function [-Wmaybe-uninitialized]
   45 |         swap(a[answ], a[a.size() - 1]);
      |                    ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -