# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
654405 | Hiennoob123 | Xylophone (JOI18_xylophone) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "library.h"
#define ll int
//#define int long long
#define ld long double
#define cd complex<ld>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pld pair<ld,ld>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std ;
ll n ;
bool check[1005] ;
ll deg[1005] ;
vector<ll> T[1005] ;
vector<pll> Edge ;
ll cnt_query= 0 ;
ll ask(ll l , ll r , ll num)
{
vector<ll> que1(n , 0) , que2(n , 0) ;
que1[num-1] = 1 ;
for(int i = l ; i<= r ; i++)
{
que1[i-1] = que2[i-1] = 1 ;
}
cnt_query += 2 ;
if(cnt_query>20000)
{
//exit(69);
}
return (r-l+2-Query(que1)) - (r-l+1-Query(que2)) ;
}
void dnc(ll l , ll r , ll num)
{
if(deg[num]==2) return ;
if(r-l<1)
{
return ;
}
//cout << l << " " << r << " " << num << "\n" ;
ll mid = ((l+r)>>1) ;
ll this1 = ask(l , mid , num) ;
if(this1>0)
{
if(l==mid)
{
Edge.push_back(mp(num , l)) ;
}
else
{
dnc(l , mid , num) ;
}
}
deg[num] += this1 ;
if(deg[num]>=2) return ;
ll this2 = ask(mid+1 , r , num) ;
if(this2>0)
{
if(r==mid+1)
{
Edge.push_back(mp(num , r)) ;
}
else
{
dnc(mid+1 , r , num) ;
}
}
}
bool val[1005] = {} ;
void Solve(int m)
{
n = m ;
if(n==1)
{
vector<ll> ans(1 , 1) ;
Answer(ans) ;
return ;
}
//cout << n << " " << m << endl ;
for(int i = 1 ; i< n-1 ; i++)
{
dnc(i+1 , n , i) ;
}
if(n>1)
{
cnt_query += 1 ;
if(cnt_query>20000)
{
//exit(69) ;
}
vector<ll> que(n , 0);
que[n-1] = que[n-2] = 1 ;
//cout << Query(que) << "\n" ;
if(Query(que)==1) Edge.push_back(mp(n-1 , n)) ;
}
for(int i = 0; i< Edge.size() ; i++)
{
//cout << Edge[i].fi << " " << Edge[i].se << "\n" ;
T[Edge[i].fi].push_back(Edge[i].se) ;
T[Edge[i].se].push_back(Edge[i].fi) ;
}
vector<ll> ans ;
queue<ll> q ;
for(int i = 1 ; i<= n ; i++)
{
if(T[i].size()==1)
{
q.push(i) ;
break ;
}
}
while(!q.empty())
{
ll x = q.front();
q.pop() ;
if(check[x]) continue ;
check[x] = 1 ;
ans.push_back(x) ;
val[x] = 1 ;
//cout << x << " " ;
for(int i = 0; i< T[x].size() ; i++)
{
q.push(T[x][i]) ;
}
}
//for(int i = 1 ; i<= n ; i++) if(ans[i-1]!=i) cout << i << "\n" ;
//cout << cnt_query << "\n" ;
//assert(ans.size()>=n) ;
//cout << ans.size() << "-1" << endl;
Answer(ans) ;
}