답안 #765194

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
765194 2023-06-24T09:15:13 Z minhcool 도서관 (JOI18_library) C++17
100 / 100
269 ms 18436 KB
//#define local
#ifndef local
#include "library.h"
#endif
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

//#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 3e5 + 5;

const int oo = 1e18 + 7, mod = 1e9 + 7;

mt19937 rng(1);

int rnd(int l, int r){
	int temp = rng() % (r - l + 1);
	return abs(temp) + l;
}

set<int> Adj[N];

int ans[1005][1005];

int n;

#ifdef local
int Query(vector<int> v){
	cout << "? ";
	for(auto it : v) cout << it << " ";
	cout << "\n";
	int x;
	cin >> x;
	return x;
}

void Answer(vector<int> v){
	cout << "! ";
	for(auto it : v) cout << it << " ";
	cout << "\n";
	exit(0);
}
#endif

int cal(int i2, int le, int ri){
//	if(ans[le][ri]) return ans[le][ri];
	//cout << i2 << " " << le << " " << ri << "\n";
    if(le > ri) return 1;
	vector<int> v(n);
    for(int i = 0; i < n; i++) v[i] = 0;
	v[i2 - 1] = 1;
	for(int i = le - 1; i <= ri - 1; i++) v[i] = 1;
	return ans[le][ri] = Query(v);
}

bool vis[N];
vector<int> arr;

void dfs(int u, int p){
	arr.pb(u);	
	for(auto v : Adj[u]) if(v != p) dfs(v, u);
}

void Solve(int N){
	n = N;
	for(int i = 1; i < n; i++){
		int lst = i;
		while(Adj[i].size() < 2){	
			int le = lst + 1, ri = n;
			if(le > ri) break;
			//if(cal(i, lst + 1, ri) > cal(lst + 1, lst + 1, ri)) break;
			while(le < ri){
				int mid = (le + ri) >> 1;
				if(cal(i, lst + 1, mid) > cal(lst + 1, lst + 1, mid)) le = mid + 1;
				else ri = mid;
			}
			//cout << "OKAY " << i << " " << le << "\n";
			Adj[i].insert(le);
			Adj[le].insert(i);
			lst = le;
		}
	}
	vector<int> er;
	for(auto it : Adj[n]){
		if(cal(it, n, n) > 1) er.pb(it);	
	}
	for(auto it : er){
		Adj[it].erase(n);
		Adj[n].erase(it);	
	}
	int st = -1;
	for(int i = 1; i <= n; i++) if(Adj[i].size() <= 1) st = i;
	dfs(st, st);
	Answer(arr);
}

#ifdef local
void process(){
	int n;
	cin >> n;
	int x;
	for(int i = 0; i < n; i++) cin >> x;
	Solve(n);
}

signed main(){
//	ios_base::sync_with_stdio(0);
//	cin.tie(0);
	process();
}
#endif

Compilation message

library.cpp:22:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   22 | const int oo = 1e18 + 7, mod = 1e9 + 7;
      |                ~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 14956 KB # of queries: 2570
2 Correct 36 ms 14940 KB # of queries: 2540
3 Correct 41 ms 14948 KB # of queries: 2692
4 Correct 25 ms 14968 KB # of queries: 2696
5 Correct 30 ms 14936 KB # of queries: 2698
6 Correct 45 ms 14928 KB # of queries: 2728
7 Correct 32 ms 15012 KB # of queries: 2692
8 Correct 38 ms 14972 KB # of queries: 2588
9 Correct 29 ms 15032 KB # of queries: 2662
10 Correct 29 ms 14752 KB # of queries: 1586
11 Correct 7 ms 14288 KB # of queries: 0
12 Correct 8 ms 14288 KB # of queries: 1
13 Correct 5 ms 14416 KB # of queries: 4
14 Correct 9 ms 14408 KB # of queries: 8
15 Correct 7 ms 14416 KB # of queries: 88
16 Correct 8 ms 14392 KB # of queries: 216
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 14956 KB # of queries: 2570
2 Correct 36 ms 14940 KB # of queries: 2540
3 Correct 41 ms 14948 KB # of queries: 2692
4 Correct 25 ms 14968 KB # of queries: 2696
5 Correct 30 ms 14936 KB # of queries: 2698
6 Correct 45 ms 14928 KB # of queries: 2728
7 Correct 32 ms 15012 KB # of queries: 2692
8 Correct 38 ms 14972 KB # of queries: 2588
9 Correct 29 ms 15032 KB # of queries: 2662
10 Correct 29 ms 14752 KB # of queries: 1586
11 Correct 7 ms 14288 KB # of queries: 0
12 Correct 8 ms 14288 KB # of queries: 1
13 Correct 5 ms 14416 KB # of queries: 4
14 Correct 9 ms 14408 KB # of queries: 8
15 Correct 7 ms 14416 KB # of queries: 88
16 Correct 8 ms 14392 KB # of queries: 216
17 Correct 269 ms 17664 KB # of queries: 18224
18 Correct 250 ms 17612 KB # of queries: 17872
19 Correct 261 ms 17744 KB # of queries: 18118
20 Correct 193 ms 17604 KB # of queries: 16964
21 Correct 211 ms 17252 KB # of queries: 15888
22 Correct 220 ms 17628 KB # of queries: 18134
23 Correct 256 ms 17644 KB # of queries: 18102
24 Correct 94 ms 16040 KB # of queries: 8318
25 Correct 206 ms 17476 KB # of queries: 17702
26 Correct 253 ms 17432 KB # of queries: 16544
27 Correct 112 ms 16048 KB # of queries: 8276
28 Correct 208 ms 18404 KB # of queries: 17954
29 Correct 187 ms 18436 KB # of queries: 17934
30 Correct 252 ms 18400 KB # of queries: 17954