Submission #798285

#TimeUsernameProblemLanguageResultExecution timeMemory
798285lollipopFriend (IOI14_friend)C++17
100 / 100
21 ms2152 KiB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
//#define int long long
#define pb push_back
#define s second
#define f first
#define pf push_front
#define inf 100000000000000000
#define bitebi __builtin_popcountll
#define FOR( i , n ) for( int i = 0 ; i < n ; i ++ )
#define YES cout <<"YES\n"
#define NO cout << "NO\n"
#define debug cout << "Here Fine" << endl ;
#define pr pair < int , int >
#define fbo find_by_order // returns iterator
#define ook order_of_key // returns strictly less numbers than key
using namespace std ;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const double Pi=acos(-1.0);
const double EPS=1E-8;
const int mod =  1000000007 ;
const int mod1 = 998244353 ;
const int N = 2e5 + 10 ;
mt19937 R(time(0));
map < int , int > ma , ma1 ;
#include "friend.h"

pair < int , int > ans[ N ] ; 
int findSample(int n,int c[],int h[],int tp[]){
	FOR( i , n ) ans[ i ] = { c[ i ] , 0 } ; 
	for( int j = n - 1 ; j >= 1 ; j -- ){
		int hh = h[ j ] ;
		int tt = tp[ j ] ;
		int P , Q , p = ans[ hh ].f , q = ans[ hh ].s ;
		int p1 = ans[ j ].f , q1 = ans[ j ].s ;
		if( tt == 2 ){
			P = max( p + q1 , p1 + q ) ;
			Q = q1 + q ;
		}
		if( tt == 1 ){
			P = max( p + p1 , max( p + q1 , p1 + q ) ) ;
			Q = q + q1 ;
		}
		if( tt == 0 ){
			P = p + q1 ;
			Q = max( p1 + q , q1 + q ) ;
		}
		ans[ hh ] = { P , Q } ;  
	}
	return max( ans[ 0 ].f , ans[ 0 ].s ) ;
}


//#define __MAXSIZE__ 100002
//
//static int confidence[__MAXSIZE__];
//static int host[__MAXSIZE__];
//static int protocol[__MAXSIZE__];
//
//int main()
//{
//	int n,i;
//	scanf("%d",&n);
//	for(i=0;i<n;i++)
//		scanf("%d",&confidence[i]);
//	for(i=1;i<n;i++)
//		scanf("%d %d",&host[i],&protocol[i]);
//	printf("%d\n",findSample(n,confidence,host,protocol));
//	return 0;
//}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...