답안 #565907

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
565907 2022-05-21T14:11:04 Z errorgorn 도서관 (JOI18_library) C++17
100 / 100
1861 ms 616 KB
#include "library.h"

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ii pair<int,int>
#define fi first
#define se second

#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound

#define rep(x,s,e) for (int x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
vector<ii> edges; //what we have found
vector<int> al[1005];
bool vis[1005];
vector<signed> ans;

void dfs(int i){
	vis[i]=true;
	ans.pub(i);
	for (auto it:al[i]) if (!vis[it]) dfs(it);
}

int ask(int l,int r){
	set<int> s;
	rep(x,l,r+1) s.insert(x);
	
	vector<signed> v(n,0);
	for (auto it:s) v[it-1]=1;
	
	int res=sz(s)-Query(v);
	
	for (auto [a,b]:edges) if (s.count(a) && s.count(b)) res--;
	return res;
}

void Solve(signed N){
	n=N;
	
	rep(x,1,n){
		int lo=1,hi=n,mi;
		while (hi-lo>1){
			mi=hi+lo>>1;
			if (ask(1,mi)) hi=mi;
			else lo=mi;
		}
		
		int r=hi;
		lo=1,hi=r,mi;
		while (hi-lo>1){
			mi=hi+lo>>1;
			
			if (ask(mi,r)) lo=mi;
			else hi=mi;
		}
		
		edges.pub({lo,r});
	}
	
	for (auto [a,b]:edges) al[a].pub(b),al[b].pub(a);
	rep(x,1,n+1) if (sz(al[x])<=1){
		dfs(x);
		break;
	}
	
	//for (auto it:ans) cout<<it<<" "; cout<<endl;
	Answer(ans);
}

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:55:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   55 |    mi=hi+lo>>1;
      |       ~~^~~
library.cpp:61:15: warning: right operand of comma operator has no effect [-Wunused-value]
   61 |   lo=1,hi=r,mi;
      |               ^
library.cpp:63:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   63 |    mi=hi+lo>>1;
      |       ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 340 KB # of queries: 2796
2 Correct 67 ms 320 KB # of queries: 2780
3 Correct 70 ms 332 KB # of queries: 2926
4 Correct 74 ms 336 KB # of queries: 2926
5 Correct 67 ms 336 KB # of queries: 2932
6 Correct 66 ms 320 KB # of queries: 2929
7 Correct 67 ms 336 KB # of queries: 2922
8 Correct 57 ms 336 KB # of queries: 2770
9 Correct 68 ms 336 KB # of queries: 2919
10 Correct 32 ms 336 KB # of queries: 1717
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 0
13 Correct 1 ms 220 KB # of queries: 3
14 Correct 1 ms 208 KB # of queries: 10
15 Correct 2 ms 208 KB # of queries: 102
16 Correct 3 ms 208 KB # of queries: 230
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 340 KB # of queries: 2796
2 Correct 67 ms 320 KB # of queries: 2780
3 Correct 70 ms 332 KB # of queries: 2926
4 Correct 74 ms 336 KB # of queries: 2926
5 Correct 67 ms 336 KB # of queries: 2932
6 Correct 66 ms 320 KB # of queries: 2929
7 Correct 67 ms 336 KB # of queries: 2922
8 Correct 57 ms 336 KB # of queries: 2770
9 Correct 68 ms 336 KB # of queries: 2919
10 Correct 32 ms 336 KB # of queries: 1717
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 0
13 Correct 1 ms 220 KB # of queries: 3
14 Correct 1 ms 208 KB # of queries: 10
15 Correct 2 ms 208 KB # of queries: 102
16 Correct 3 ms 208 KB # of queries: 230
17 Correct 1633 ms 608 KB # of queries: 19288
18 Correct 1590 ms 380 KB # of queries: 19031
19 Correct 1663 ms 484 KB # of queries: 19257
20 Correct 1422 ms 616 KB # of queries: 18011
21 Correct 1407 ms 372 KB # of queries: 16930
22 Correct 1861 ms 380 KB # of queries: 19275
23 Correct 1808 ms 484 KB # of queries: 19230
24 Correct 460 ms 344 KB # of queries: 8882
25 Correct 1807 ms 500 KB # of queries: 18817
26 Correct 1541 ms 476 KB # of queries: 17610
27 Correct 467 ms 348 KB # of queries: 8849
28 Correct 1284 ms 380 KB # of queries: 18932
29 Correct 1205 ms 380 KB # of queries: 18911
30 Correct 1149 ms 384 KB # of queries: 18932