답안 #565868

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
565868 2022-05-21T13:19:41 Z InternetPerson10 도서관 (JOI18_library) C++17
19 / 100
366 ms 484 KB
#include <cstdio>
#include <vector>
#include <bits/stdc++.h>
#include "library.h"
using namespace std;

vector<vector<int>> nums;

int N;

int ask(vector<int> v) {
    vector<int> q(N, 0);
    for(int i = 0; i < v.size(); i++) {
        if(v[i] == 1) {
            for(int g : nums[i]) q[g] = 1;
        }
    }
    return Query(q);
}

bool validCombine(int x, int y) {
    vector<int> q(N, 0);
    q[nums[x].back()] = 1;
    q[nums[y][0]] = 1;
    return (Query(q) == 1);
}

void combine(int x, int y) { 
    bool ok = validCombine(x, y);
    if(!ok) {
        reverse(nums[x].begin(), nums[x].end());
        ok = validCombine(x, y);
    }
    if(!ok) {
        reverse(nums[y].begin(), nums[y].end());
        ok = validCombine(x, y);
    }
    if(!ok) {
        reverse(nums[x].begin(), nums[x].end());
    }
    vector<vector<int>> nums2;
    for(int i = 0; i < nums.size(); i++) {
        if(i != x && i != y) nums2.push_back(nums[i]);
    }
    nums2.push_back(nums[x]);
    for(int g : nums[y]) nums2.back().push_back(g);
    nums = nums2;
}

void smallSolve(int n) { // Finds two magkatabi
    if(n == 2) {
        combine(0, 1);
        return;
    }
    vector<int> good(n, 1);
    vector<int> v;
    int x = n;
    while(x != 2) {
        for(int i = 0; i < n; i++) {
            if(good[i]) v.push_back(i);
        }
        int res = (x+1)/2;
        vector<int> test;
        while(res == (x+1)/2) {
            test = good;
            random_shuffle(v.begin(), v.end());
            for(int i = 0; i < x/2; i++) test[v[i]] = 0;
            res = ask(test);
        }
        good = test;
        x = (x+1) / 2;
        v.clear();
    }
    int a = -1, b = -1;
    for(int i = 0; i < n; i++) {
        if(good[i]) {
            a = b;
            b = i;
        }
    }
    combine(a, b);
}

void Solve(int m) {
    N = m;
    srand(time(NULL));
    nums.resize(N);
    for(int i = 0; i < N; i++) nums[i].push_back(i);
    for(int i = N; i > 1; i--) {
        smallSolve(i);
        /*
        for(vector<int> v : nums) {
            for(int g : v) {
                cout << g << ' ';
            }
            cout << '\n';
        }
        cout << "-\n";
        */
    }
    for(int i = 0; i < N; i++) nums[0][i]++;
    Answer(nums[0]);
}

Compilation message

library.cpp: In function 'int ask(std::vector<int>)':
library.cpp:13:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for(int i = 0; i < v.size(); i++) {
      |                    ~~^~~~~~~~~~
library.cpp: In function 'void combine(int, int)':
library.cpp:42:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for(int i = 0; i < nums.size(); i++) {
      |                    ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 348 KB # of queries: 2957
2 Correct 46 ms 340 KB # of queries: 2987
3 Correct 41 ms 472 KB # of queries: 3017
4 Correct 47 ms 464 KB # of queries: 3043
5 Correct 40 ms 364 KB # of queries: 3057
6 Correct 38 ms 348 KB # of queries: 2982
7 Correct 47 ms 484 KB # of queries: 3023
8 Correct 56 ms 460 KB # of queries: 2899
9 Correct 46 ms 344 KB # of queries: 3102
10 Correct 24 ms 208 KB # of queries: 1820
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 1
13 Correct 0 ms 208 KB # of queries: 3
14 Correct 0 ms 208 KB # of queries: 8
15 Correct 1 ms 208 KB # of queries: 89
16 Correct 3 ms 208 KB # of queries: 221
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 348 KB # of queries: 2957
2 Correct 46 ms 340 KB # of queries: 2987
3 Correct 41 ms 472 KB # of queries: 3017
4 Correct 47 ms 464 KB # of queries: 3043
5 Correct 40 ms 364 KB # of queries: 3057
6 Correct 38 ms 348 KB # of queries: 2982
7 Correct 47 ms 484 KB # of queries: 3023
8 Correct 56 ms 460 KB # of queries: 2899
9 Correct 46 ms 344 KB # of queries: 3102
10 Correct 24 ms 208 KB # of queries: 1820
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 1
13 Correct 0 ms 208 KB # of queries: 3
14 Correct 0 ms 208 KB # of queries: 8
15 Correct 1 ms 208 KB # of queries: 89
16 Correct 3 ms 208 KB # of queries: 221
17 Runtime error 366 ms 428 KB Execution killed with signal 13
18 Halted 0 ms 0 KB -