Submission #1118320

# Submission time Handle Problem Language Result Execution time Memory
1118320 2024-11-25T08:59:41 Z thelegendary08 Library (JOI18_library) C++17
100 / 100
457 ms 604 KB
#include "library.h"
#include<bits/stdc++.h>
#define vi vector<int>
#define vb vector<bool>
#define pb push_back
#define f0r(i,n) for(int i = 0; i<n; i++)
#define FOR(i, k, n) for(int i = k; i<n; i++)
using namespace std;
int n;
int solve(int prev, vi &v, int l, int r){
	if(l == r){
		return l;
	}
	int mid = (l + r)/2;
	vi quer(n);
	for(int i = l; i<=mid; i++){
		quer[v[i]] = 1;
	}
	quer[prev] = 1;
	int a1 = Query(quer);
	quer[prev] = 0;
	int a2 = Query(quer);
	if(a1 == a2){
		return solve(prev, v, l, mid);
	}
	else{
		return solve(prev, v, mid+1, r);
	}
}
void Solve(int n)
{
	if(n == 1)Answer({1});
	else{
		::n = n;
		int ret;
		int st;
		f0r(i, n){
			vi quer(n);
			f0r(j,n){
				if(j != i)quer[j] = 1;
			}
			//for(auto u : quer)cout<<u<<' ';
			//cout<<'\n';
			ret = Query(quer);
			if(ret == 1){
				st = i;
				break;
			}
		}
		//cout<<st<<'\n';
		vi ans(n);
		ans[0] = st;
		
		vb vis(n,0);
		vis[st] = 1;
		int prev = st;
		FOR(i, 1, n){
			vi cur;
			f0r(j,n){
				if(!vis[j])cur.pb(j);
			}
			int m = cur.size();
			int nxt = solve(prev, cur, 0, m-1);
			nxt = cur[nxt];
			ans[i] = nxt;
			prev = nxt;
			vis[nxt] = 1;
		}
	
		f0r(i,n)ans[i]++;
		//for(auto u : ans)cout<<u<<' ';
		//cout<<'\n';
		Answer(ans);
	}
	
}
# Verdict Execution time Memory Grader output
1 Correct 52 ms 348 KB # of queries: 2387
2 Correct 44 ms 348 KB # of queries: 2433
3 Correct 51 ms 348 KB # of queries: 2638
4 Correct 55 ms 348 KB # of queries: 2593
5 Correct 59 ms 348 KB # of queries: 2504
6 Correct 47 ms 604 KB # of queries: 2553
7 Correct 56 ms 348 KB # of queries: 2568
8 Correct 45 ms 348 KB # of queries: 2402
9 Correct 58 ms 348 KB # of queries: 2512
10 Correct 29 ms 604 KB # of queries: 1478
11 Correct 1 ms 348 KB # of queries: 0
12 Correct 1 ms 336 KB # of queries: 1
13 Correct 1 ms 340 KB # of queries: 4
14 Correct 1 ms 336 KB # of queries: 7
15 Correct 3 ms 336 KB # of queries: 73
16 Correct 4 ms 336 KB # of queries: 187
# Verdict Execution time Memory Grader output
1 Correct 52 ms 348 KB # of queries: 2387
2 Correct 44 ms 348 KB # of queries: 2433
3 Correct 51 ms 348 KB # of queries: 2638
4 Correct 55 ms 348 KB # of queries: 2593
5 Correct 59 ms 348 KB # of queries: 2504
6 Correct 47 ms 604 KB # of queries: 2553
7 Correct 56 ms 348 KB # of queries: 2568
8 Correct 45 ms 348 KB # of queries: 2402
9 Correct 58 ms 348 KB # of queries: 2512
10 Correct 29 ms 604 KB # of queries: 1478
11 Correct 1 ms 348 KB # of queries: 0
12 Correct 1 ms 336 KB # of queries: 1
13 Correct 1 ms 340 KB # of queries: 4
14 Correct 1 ms 336 KB # of queries: 7
15 Correct 3 ms 336 KB # of queries: 73
16 Correct 4 ms 336 KB # of queries: 187
17 Correct 438 ms 336 KB # of queries: 18008
18 Correct 397 ms 440 KB # of queries: 17231
19 Correct 427 ms 444 KB # of queries: 17451
20 Correct 383 ms 504 KB # of queries: 16277
21 Correct 346 ms 596 KB # of queries: 15362
22 Correct 443 ms 452 KB # of queries: 17617
23 Correct 409 ms 336 KB # of queries: 17170
24 Correct 193 ms 340 KB # of queries: 7885
25 Correct 425 ms 348 KB # of queries: 17118
26 Correct 377 ms 348 KB # of queries: 15989
27 Correct 184 ms 604 KB # of queries: 7994
28 Correct 434 ms 348 KB # of queries: 17935
29 Correct 449 ms 336 KB # of queries: 17915
30 Correct 457 ms 336 KB # of queries: 17935