Submission #413433

#TimeUsernameProblemLanguageResultExecution timeMemory
413433ritul_kr_singhLibrary (JOI18_library)C++17
0 / 100
59 ms408 KiB
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define sp << ' ' <<
#define nl << '\n'
 
#include "library.h"
 
void Solve(int n){
	vector<array<int, 2>> e;
	vector<int> g[n], q(n), ans(n);
 
	for(int _=1; _<n; ++_){
		int low = 0, high = n-1;
		while(low < high){
			int mid = (low + high) / 2;
			int exp = mid + 1;
			for(auto &i : e) if(i[0] <= mid && i[1] <= mid) --exp;
			for(int i=0; i<n; ++i) q[i] = i <= mid;
 
			if(Query(q) == exp) low = mid + 1;
			else high = mid;
		}
 
		int x = low; low = 0, high = x-1;
 
		while(low < high){
			int mid = (low + high) / 2;
			int exp = mid + 1;
			for(auto &i : e) if(i[0] <= mid && (i[1] <= mid || i[1] == x)) --exp;
			for(int i=0; i<n; ++i) q[i] = i <= mid || i == x;
 
			if(Query(q) <= exp) high = mid;
			else low = mid + 1;
		}
 
		e.push_back({low, x});
		g[low].push_back(x);
		g[x].push_back(low);
	}
 
	int u;
	for(int i=0; i<n; ++i) if((int)g[i].size() == 1) u = i;
	for(int i=0; i<n; ++i){
		ans[i] = u + 1;
		if(i == n-1) break;
		u = g[u][i && g[u][0] + 1 == ans[i-1]];
	}
  	
  	for(int i : ans) assert(1 <= i && i <= n);
 
	Answer(ans);
}

Compilation message (stderr)

library.cpp: In function 'void Solve(int)':
library.cpp:45:14: warning: 'u' may be used uninitialized in this function [-Wmaybe-uninitialized]
   45 |   ans[i] = u + 1;
      |            ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...