Submission #412081

# Submission time Handle Problem Language Result Execution time Memory
412081 2021-05-26T13:33:49 Z benedict0724 Library (JOI18_library) C++17
0 / 100
41 ms 560 KB
#include <cstdio>
#include <vector>
#include <assert.h>
#include "library.h"
using namespace std;

vector<int> adj[1000];
int lin[1000], U[1000];
int _find(int x)
{
    if(x == lin[x]) return x;
    return lin[x] = _find(lin[x]);
}

void Solve(int N)
{
	vector<int> M(N);
	for(int i=0;i<N;i++) adj[i].clear();
	for(int i=0;i<N;i++) M[i] = 0;
	M[0] = 1;
	int P = 0;
	for(int i = 1; i < N; i++) {
        int l = 0, r = i-1;
        M[i] = 1;
        int Q = Query(M);
        if(P < Q) { P = Q; continue; }
        while(l < r)
        {
            vector<int> v(N);
            int mid = (l + r)/2;
            for(int j=0;j<N;j++) v[j] = 0;
            for(int j=0;j<=mid;j++) v[j] = 1;
            int A, B;
            A = Query(v);
            v[i] = 1;
            B = Query(v);

            if(A >= B) r = mid;
            else l = mid+1;
        }
        adj[i].push_back(l);
        adj[l].push_back(i);

        if(P == Q) continue;
        l = 0, r = i-1;
        while(l < r)
        {
            vector<int> v(N);
            int mid = (l + r)/2;
            for(int j=0;j<N;j++) v[j] = 0;
            for(int j=0;j<=mid;j++) v[j] = 1;
            int A, B;
            A = Query(v);
            v[i] = 1;
            B = Query(v);
            if(A > B) r = mid;
            else l = mid+1;
        }

        adj[l].push_back(i);
        adj[i].push_back(l);

        P = Q;
	}

	vector<int> res(N);

	int st = -1;
	for(int i=0;i<N;i++) if(adj[i].size() == 1) st = i;
	for(int i=0,now=st;i<N;i++)
    {
        res[i] = now+1;
        int tmp = -1;
        for(int nxt : adj[now])
        {
            if(!U[nxt]) tmp = nxt;
        }
        U[now] = 1;
        assert(tmp != -1);
        now = tmp;
    }

	Answer(res);
}
# Verdict Execution time Memory Grader output
1 Runtime error 41 ms 560 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 41 ms 560 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -