Submission #413449

# Submission time Handle Problem Language Result Execution time Memory
413449 2021-05-28T17:57:56 Z ritul_kr_singh Library (JOI18_library) C++17
100 / 100
416 ms 448 KB
#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);
	}
  
  	if(n == 1){
      ans[0] = 1;
      Answer(ans);
      return;
    }
 
	int u;
	for(int i=0; i<n; ++i) if((int)g[i].size() == 1) u = i;
  	assert(u >= 0);
	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]];
	}
 
	Answer(ans);
}

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:52:14: warning: 'u' may be used uninitialized in this function [-Wmaybe-uninitialized]
   52 |   ans[i] = u + 1;
      |            ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 51 ms 200 KB # of queries: 2793
2 Correct 45 ms 288 KB # of queries: 2772
3 Correct 53 ms 280 KB # of queries: 2917
4 Correct 58 ms 284 KB # of queries: 2923
5 Correct 32 ms 272 KB # of queries: 2909
6 Correct 53 ms 292 KB # of queries: 2915
7 Correct 28 ms 288 KB # of queries: 2929
8 Correct 65 ms 200 KB # of queries: 2799
9 Correct 55 ms 200 KB # of queries: 2922
10 Correct 39 ms 276 KB # of queries: 1707
11 Correct 1 ms 200 KB # of queries: 0
12 Correct 1 ms 200 KB # of queries: 1
13 Correct 1 ms 200 KB # of queries: 4
14 Correct 1 ms 200 KB # of queries: 10
15 Correct 4 ms 200 KB # of queries: 100
16 Correct 4 ms 200 KB # of queries: 226
# Verdict Execution time Memory Grader output
1 Correct 51 ms 200 KB # of queries: 2793
2 Correct 45 ms 288 KB # of queries: 2772
3 Correct 53 ms 280 KB # of queries: 2917
4 Correct 58 ms 284 KB # of queries: 2923
5 Correct 32 ms 272 KB # of queries: 2909
6 Correct 53 ms 292 KB # of queries: 2915
7 Correct 28 ms 288 KB # of queries: 2929
8 Correct 65 ms 200 KB # of queries: 2799
9 Correct 55 ms 200 KB # of queries: 2922
10 Correct 39 ms 276 KB # of queries: 1707
11 Correct 1 ms 200 KB # of queries: 0
12 Correct 1 ms 200 KB # of queries: 1
13 Correct 1 ms 200 KB # of queries: 4
14 Correct 1 ms 200 KB # of queries: 10
15 Correct 4 ms 200 KB # of queries: 100
16 Correct 4 ms 200 KB # of queries: 226
17 Correct 394 ms 440 KB # of queries: 19260
18 Correct 356 ms 440 KB # of queries: 19010
19 Correct 386 ms 448 KB # of queries: 19240
20 Correct 359 ms 428 KB # of queries: 18005
21 Correct 351 ms 312 KB # of queries: 16917
22 Correct 407 ms 436 KB # of queries: 19279
23 Correct 416 ms 440 KB # of queries: 19218
24 Correct 160 ms 300 KB # of queries: 8875
25 Correct 303 ms 440 KB # of queries: 18825
26 Correct 332 ms 328 KB # of queries: 17599
27 Correct 98 ms 308 KB # of queries: 8842
28 Correct 358 ms 332 KB # of queries: 17944
29 Correct 398 ms 332 KB # of queries: 17924
30 Correct 278 ms 336 KB # of queries: 17944