답안 #761253

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
761253 2023-06-19T12:01:03 Z Dan4Life 도서관 (JOI18_library) C++17
100 / 100
250 ms 592 KB
#include <bits/stdc++.h>
#include "library.h"
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
int n;
vector<pair<int,int>> ed;
vector<int> ans, adj[1500];
 
void dfs(int s, int p){
	ans.pb(s);
	for(auto u : adj[s])
		if(u!=p) dfs(u,s); 
}
 
int chk(int l, int r, int q){
	int ans = 0;
	for(auto [a,b] : ed) ans+=a>=l and b<=r;
	return r-l+1-q-ans>0;
}
 
void Solve(int N)
{
	n = N; int tot = 0;
	vector<int> M(N,0);
	while(tot<n-1){
		int l = 1, r = n;
		while(l<r){
			int mid = (l+r)/2;
			fill(begin(M),begin(M)+mid,1);
			if(chk(1,mid,Query(M))) r=mid;
			else l=mid+1;
			fill(begin(M),begin(M)+mid,0);
		}
		int i = l;
		l = 1, r = i;
		while(l<r){
			int mid = (l+r+1)/2;
			fill(begin(M)+mid-1,begin(M)+i,1);
			if(chk(mid,i,Query(M))) l=mid;
			else r=mid-1;
			fill(begin(M)+mid-1,begin(M)+i,0);
		}
		adj[i].pb(l), adj[l].pb(i), ed.pb({l,i}); tot++;
	}
	for(int i = 1; i <= N; i++){
		if(sz(adj[i])<=1){
			dfs(i,-1), Answer(ans);
			return;
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 336 KB # of queries: 2790
2 Correct 40 ms 336 KB # of queries: 2779
3 Correct 34 ms 340 KB # of queries: 2933
4 Correct 31 ms 332 KB # of queries: 2926
5 Correct 26 ms 344 KB # of queries: 2933
6 Correct 18 ms 348 KB # of queries: 2924
7 Correct 33 ms 336 KB # of queries: 2915
8 Correct 30 ms 332 KB # of queries: 2791
9 Correct 34 ms 336 KB # of queries: 2922
10 Correct 21 ms 208 KB # of queries: 1714
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 2
13 Correct 0 ms 208 KB # of queries: 5
14 Correct 0 ms 208 KB # of queries: 11
15 Correct 1 ms 336 KB # of queries: 103
16 Correct 2 ms 208 KB # of queries: 232
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 336 KB # of queries: 2790
2 Correct 40 ms 336 KB # of queries: 2779
3 Correct 34 ms 340 KB # of queries: 2933
4 Correct 31 ms 332 KB # of queries: 2926
5 Correct 26 ms 344 KB # of queries: 2933
6 Correct 18 ms 348 KB # of queries: 2924
7 Correct 33 ms 336 KB # of queries: 2915
8 Correct 30 ms 332 KB # of queries: 2791
9 Correct 34 ms 336 KB # of queries: 2922
10 Correct 21 ms 208 KB # of queries: 1714
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 2
13 Correct 0 ms 208 KB # of queries: 5
14 Correct 0 ms 208 KB # of queries: 11
15 Correct 1 ms 336 KB # of queries: 103
16 Correct 2 ms 208 KB # of queries: 232
17 Correct 249 ms 344 KB # of queries: 19255
18 Correct 212 ms 592 KB # of queries: 19036
19 Correct 242 ms 460 KB # of queries: 19250
20 Correct 218 ms 356 KB # of queries: 18005
21 Correct 227 ms 356 KB # of queries: 16936
22 Correct 195 ms 364 KB # of queries: 19279
23 Correct 238 ms 364 KB # of queries: 19240
24 Correct 87 ms 336 KB # of queries: 8868
25 Correct 249 ms 356 KB # of queries: 18804
26 Correct 227 ms 360 KB # of queries: 17594
27 Correct 109 ms 336 KB # of queries: 8839
28 Correct 218 ms 336 KB # of queries: 18943
29 Correct 250 ms 460 KB # of queries: 18922
30 Correct 217 ms 460 KB # of queries: 18943