답안 #74154

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
74154 2018-08-30T10:18:32 Z zscoder popa (BOI18_popa) C++17
100 / 100
86 ms 712 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "popa.h"

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

/*
int secret[1111];
int queries;
int query(int a, int b, int c, int d)
{
	int gd1=secret[a]; int gd2=secret[c];
	for(int i=a;i<=b;i++) gd1=__gcd(gd1,secret[i]);
	for(int i=c;i<=d;i++) gd2=__gcd(gd2,secret[i]);
	queries++;
	return (gd1==gd2);
}
*/

int ansL[1111];
int ansR[1111];

int solve(int n, int *L, int *R)
{
	for(int i=0;i<n;i++) ansL[i]=ansR[i]=-1;
	int rt=0;
	for(int i=1;i<n;i++)
	{
		int cur = rt;
		vi vec;
		while(cur!=-1)
		{
			vec.pb(cur); cur=ansR[cur];
		}
		int child=int(vec.size());
		for(int j=int(vec.size())-1;j>=0;j--)
		{
			if(query(i,i,vec[j],i))
			{
				child=j;
			}
			else break;
		}
		vec.pb(-1);
		ansL[i] = vec[child];
		if(child>0)
		{
			ansR[vec[child-1]]=i;
		}
		else
		{
			rt=i;
		}
	}
	for(int i=0;i<n;i++)
	{
		L[i] = ansL[i]; R[i] = ansR[i];
	}
	return rt;
}

/*
int n; 
void read_input()
{
	cin>>n;
	//n=1000;
	for(int i=0;i<n;i++)
	{
		//secret[i]=1;
		cin>>secret[i];
	}
}

int secretL[1111];
int secretR[1111];

void process_case()
{
	read_input(); queries=0;
	int rt = solve(n, secretL, secretR);
	cerr<<"ROOT : "<<secret[rt]<<'\n';
	for(int i=0;i<n;i++)
	{
		cerr<<secret[i]<<' '<<(secretL[i]==-1?-1:secret[secretL[i]])<<' '<<(secretR[i]==-1?-1:secret[secretR[i]])<<'\n';
	}
	cerr<<"QUERIES USED : "<<ld(queries)/ld(n)<<'\n';
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	process_case();	
}	
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 276 KB Output is correct
2 Correct 11 ms 324 KB Output is correct
3 Correct 10 ms 528 KB Output is correct
4 Correct 10 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 588 KB Output is correct
2 Correct 73 ms 588 KB Output is correct
3 Correct 51 ms 588 KB Output is correct
4 Correct 72 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 684 KB Output is correct
2 Correct 81 ms 712 KB Output is correct
3 Correct 86 ms 712 KB Output is correct
4 Correct 70 ms 712 KB Output is correct