답안 #970971

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
970971 2024-04-27T16:16:13 Z jhon06 Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
14 ms 1036 KB
#include<bits/stdc++.h>
//#include<bits/extc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define maxl 1e18
#define minl -(1e18)
#define lb lower_bound
#define ub upper_bound
#define bg begin()
#define nd end()
#define rnd(x) random_shuffle((x).begin, (x).end())
#define reverse(x) reverse((x).begin(), (x).end())
#define del erase
#define ssub substr
#define tp tuple
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define vi vector<ll>
#define vii vector<pair<ll,ll>>
#define lsb(x) (x&(-x))
#define log2(i) (__builtin_clzll(1) - __builtin_clzll(i))
#define gcd(a,b) __gcd(a,b)
#define bits(a) __builtin_popcountll(a)
#define lcm(a,b) ((a*b)/gcd(a,b))
#define dbg(x) (cerr<<"["<<"R"<<":"<<__LINE__<<"]"<<#x<<" -> "<<(x)<<'\n',(x))
#define remDup(x) sort(all(x));x.erase(unique(all(x)),(x).end())
// #define rand (rand() * (RAND_MAX + 1) + rand()) % (int)1e6
#define count(x) __builtin_popcount(x)
//nth elemtnh
 
const int fi[]={+1,0,-1,+0};
const int fj[]={+0,-1,0,+1};
bool valid(int i,int j,int n,int m){
	return i>=0 && j>=0 && i<n && j<m;
}
//g++ main.cpp -o a -Wall -Wextra -Wshadow -fsanitize=address,undefined -ggdb3 -fmax-errors=10 -02
//cout << setprecision(10) << fixed << sol << '\n'; se voglio specificare precisione
//lower_bound(arr,arr+a,valore); unique() remove dups fill(vec,number) merge() binary_search()
//(p % n + n) % n
//order_of_key(n), find_by_order(n) , size( //0 based
//strstr  per trovare se sottostringa appare in stringa 0(n)
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
using namespace std;
int query(vector < int > islands);
vector<vector<int>> adj;
vector<int> nodes;
void dfs(int node,int p){
	nodes.pb(node);
	for(auto x: adj[node]){
		if(x==p)continue;
		dfs(x,node);
	}
}
int findEgg(int N, vector < pair < int, int > > bridges){
	adj=vector<vector<int>>(N+1,vector<int>());
	nodes.clear();
	for(auto x: bridges){
		adj[x.first].pb(x.second);
		adj[x.second].pb(x.first);
	}
	dfs(1,0);
	int l=0;
	int r=N-1;
	while(l<r){
		int mid=(l+r+1)/2;
		if(query(vector<int>(nodes.begin(),nodes.begin()+mid))){
			r=mid-1;
		}
		else l=mid;
	}
	return nodes[l];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Number of queries: 4
2 Correct 1 ms 344 KB Number of queries: 4
3 Correct 1 ms 344 KB Number of queries: 4
4 Correct 1 ms 344 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 728 KB Number of queries: 8
2 Correct 8 ms 728 KB Number of queries: 9
3 Correct 14 ms 988 KB Number of queries: 9
4 Correct 11 ms 480 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 1036 KB Number of queries: 9
2 Correct 10 ms 732 KB Number of queries: 9
3 Correct 12 ms 728 KB Number of queries: 9
4 Correct 10 ms 504 KB Number of queries: 9