Submission #827821

# Submission time Handle Problem Language Result Execution time Memory
827821 2023-08-16T19:51:11 Z MohamedAhmed04 Library (JOI18_library) C++14
0 / 100
24 ms 336 KB
#include <bits/stdc++.h>
#include "library.h"

using namespace std;

const int MAX = 1000 + 10 ;

int n ;

vector<int>v[MAX] ;
int taken[MAX] ;

bool check(int l , int r)
{
	vector<int>vq(n , 0) ;
	int cnt = r-l+1 ;
	for(int i = l ; i <= r ; ++i)
	{
		vq[i] = 1 ;
		for(auto &j : v[i])
			cnt -= (j > i && j <= r) ;
	}
	return (Query(vq) < cnt) ;
}

void Find_Adjacent(int idx , int cnt)
{
	for(int i = 0 ; i < cnt ; ++i)
	{
		int l = 0 , r = idx ;
		int idx2 = -1 ; 
		while(l <= r)
		{
			int mid = (l + r) >> 1 ;
			if(check(mid , idx))
				idx2 = mid , l = mid+1 ;
			else
				r = mid-1 ;
		}
		v[idx].push_back(idx2) , v[idx2].push_back(idx) ;
	}
}

void Solve(int N)
{
	n = N ;
	vector<int>vq(n , 0) ;
	int cur = 0 ;
	for(int i = 0 ; i < n ; ++i)
	{
		++cur ;
		vq[i] = 1 ;
		int x = Query(vq) ;
		Find_Adjacent(i , cur - x) ;
		cur = x ;
	}
	vector<int>ans ;
	int x = -1 ;
	for(int i = 0 ; i < n ; ++i)
	{
		if(v[i].size() == 1)
		{
			x = i ;
			break ;
		}
	}
	while(ans.size() < n)
	{
		ans.push_back(x+1) ;
		taken[x] = 1 ;
		for(auto &i : v[x])
		{
			if(!taken[i])
			{
				x = i ;
				break ;
			}
		}
	}
	Answer(ans) ;
}

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:67:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   67 |  while(ans.size() < n)
      |        ~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 21 ms 208 KB # of queries: 1525
2 Correct 15 ms 336 KB # of queries: 1522
3 Correct 16 ms 208 KB # of queries: 1599
4 Correct 21 ms 324 KB # of queries: 1587
5 Correct 23 ms 324 KB # of queries: 1597
6 Correct 20 ms 208 KB # of queries: 1587
7 Correct 24 ms 316 KB # of queries: 1591
8 Correct 21 ms 208 KB # of queries: 1522
9 Correct 17 ms 208 KB # of queries: 1597
10 Correct 11 ms 328 KB # of queries: 953
11 Incorrect 0 ms 208 KB Wrong Answer [5]
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 208 KB # of queries: 1525
2 Correct 15 ms 336 KB # of queries: 1522
3 Correct 16 ms 208 KB # of queries: 1599
4 Correct 21 ms 324 KB # of queries: 1587
5 Correct 23 ms 324 KB # of queries: 1597
6 Correct 20 ms 208 KB # of queries: 1587
7 Correct 24 ms 316 KB # of queries: 1591
8 Correct 21 ms 208 KB # of queries: 1522
9 Correct 17 ms 208 KB # of queries: 1597
10 Correct 11 ms 328 KB # of queries: 953
11 Incorrect 0 ms 208 KB Wrong Answer [5]
12 Halted 0 ms 0 KB -