Submission #1364967

#TimeUsernameProblemLanguageResultExecution timeMemory
1364967coderg300711Closing Time (IOI23_closing)C++20
Compilation error
0 ms0 KiB
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pii pair<int,int>
#define pll pair<long long,long long>
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define pb push_back
#define sz(x) (int)(x).size()
#define rsz resize
#define ass assign
#define F(i,l,r) for(int i=(l);i<(r);++i)
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
template<typename T> using pqg = priority_queue<T, vector<T>, greater<T>>;
#define each(a,x) for(auto a:x)
#define FOR(i,a) for(int i=0;i<(a);i++)
#define ROF(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define eb emplace_back
#define ft front()
#define V vector

#include "closing.h"

struct edge{
	int to,w;
};

V<ll> get_dist(int st,int n,const V<V<edge>>& adj){
	V<ll> dist(n,-1);
	dist[st]=0;
	pqg<pair<ll,int>> pq;
	pq.push({0,st});
	while(!pq.empty()){
		ll d=pq.top().fi;
		int u=pq.top().se;
		pq.pop();
		if(d>dist[u])continue;
		each(e,adj[u]){
			if(!~dist[e.to] || dist[u]+e.w<dist[e.to]){
				dist[e.to]=dist[u]+e.w;
				pq.puhs({dist[e.to],e.to});
			}
		}
	}
	return dist;
}

int max_score(int n,int x,int u,ll k,V<int> u,V<int> v,V<int> w){
	V<V<edge>> adj(n);
	V<int> deg(n,0);
	FOR(i,n-1){
		adj[u[i]].pb({v[i],w[i]});
		adj[v[i]].pb({u[i],w[i]});
		deg[u[i]]++;
		deg[v[i]]++;
	}
	V<ll> dx=get_dist(x,n,adj),dy=get_dist(y,n,adj);
	V<ll> pool;
	FOR(i,n){
		if(i!=x)pool.pb(dx[i]);
		if(i!=y)pool.pb(dy[i]);
	}
	sort(pool.begin(),pool.end());
	int res=2;
	ll curk=0;
	each(v,pool){
		if(curk+v<=k){
			curk+=v;
			res++;
		}else break;
	}
	bool linear=1;
	each(d,deg){
		if(d>2){
			linear=0;
			break;
		}
	}
	if(!linear || n>500)return res;
	V<int> line;
	int st=0;
	FOR(i,n){
		if(deg[i]==1){
			st=i;
			break;
		}
	}
	V<bool> vis(n,0);
	int cur=st;
	while(sz(line)<n){
		line.pb(cur);
		vis[cur]=1;
		each(e,adj[cur]){
			if(!vis[e.to]){
				cur=e.to;
				break;
			}
		}
	}
	V<int> pos(n);
	FOR(i,n)pos[line[i]]=i;
	int overlap=0;
	FOR(l,n){
		F(r,l,n){
			int vl=line[l],vr=line[r];
			int reachxl=min(pos[x],l),reachxr=max(pos[x],r);
			int reachyl=min(pos[y],l),reachyr=max(pos[y],r);
			ll cost=0;
			int score=0;
			FOR(i,n){
				bool inx=(pos[i]>=reachxl && pos[i]<=reachxr);
				bool iny=(pos[i]>=reachyl && pos[i]<=reachyr);
				if(inx && iny){
					cost+=max(dx[i],dy[i]);
					score+=2;
				}else if(inx){
					cost+=dx[i];
					score++;
				}else if(iny){
					cost+=dy[i];
					score++;
				}
			}
			if(cost<=k){
				ll rem=k-cost;
				int ul=min(reachxl,reachyl),ur=max(reachxr,reachyr);
				int curl=ul-1,curr=ur+1;
				while(curl>=0 || curr<n){
					ll costl=(curl>=0)?min(dx[line[curl]],dy[line[curl]]):k+7;
					ll costr=(curr<n)?min(dx[line[curr]],dy[line[curr]]):k+7;
					if(costl<costr){
						if(rem>=costl){
							rem-=costl;
							score++;
							curl--;
						}else break;
					}else{
						if(rem>=costr){
							rem-=costr;
							score++;
							curr++;
						}else break;
					}
				}
				overlap=max(overlap,score);
			}
		}
	}
	return max(res,overlap);
}

Compilation message (stderr)

closing.cpp: In function 'std::vector<long long int> get_dist(int, int, const std::vector<std::vector<edge> >&)':
closing.cpp:45:36: error: 'pqg<std::pair<long long int, int> >' {aka 'class std::priority_queue<std::pair<long long int, int>, std::vector<std::pair<long long int, int>, std::allocator<std::pair<long long int, int> > >, std::greater<std::pair<long long int, int> > >'} has no member named 'puhs'; did you mean 'push'?
   45 |                                 pq.puhs({dist[e.to],e.to});
      |                                    ^~~~
      |                                    push
closing.cpp: At global scope:
closing.cpp:52:45: error: conflicting declaration 'std::vector<int> u'
   52 | int max_score(int n,int x,int u,ll k,V<int> u,V<int> v,V<int> w){
      |                                             ^
closing.cpp:52:31: note: previous declaration as 'int u'
   52 | int max_score(int n,int x,int u,ll k,V<int> u,V<int> v,V<int> w){
      |                           ~~~~^
closing.cpp: In function 'int max_score(...)':
closing.cpp:56:22: error: invalid types 'int[int]' for array subscript
   56 |                 adj[u[i]].pb({v[i],w[i]});
      |                      ^
closing.cpp:57:32: error: invalid types 'int[int]' for array subscript
   57 |                 adj[v[i]].pb({u[i],w[i]});
      |                                ^
closing.cpp:57:29: error: no matching function for call to 'std::vector<edge>::push_back(<brace-enclosed initializer list>)'
   57 |                 adj[v[i]].pb({u[i],w[i]});
      |                 ~~~~~~~~~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53,
                 from closing.cpp:1:
/usr/include/c++/13/bits/stl_vector.h:1281:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = edge; _Alloc = std::allocator<edge>; value_type = edge]'
 1281 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<edge>::value_type&' {aka 'const edge&'}
 1281 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_vector.h:1298:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = edge; _Alloc = std::allocator<edge>; value_type = edge]'
 1298 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1298:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<edge>::value_type&&' {aka 'edge&&'}
 1298 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
closing.cpp:58:22: error: invalid types 'int[int]' for array subscript
   58 |                 deg[u[i]]++;
      |                      ^
closing.cpp:61:48: error: 'y' was not declared in this scope; did you mean 'dy'?
   61 |         V<ll> dx=get_dist(x,n,adj),dy=get_dist(y,n,adj);
      |                                                ^
      |                                                dy
closing.cpp:116:70: error: 'reachyr' was not declared in this scope; did you mean 'reachyl'?
  116 |                                 bool iny=(pos[i]>=reachyl && pos[i]<=reachyr);
      |                                                                      ^~~~~~~
      |                                                                      reachyl
closing.cpp:130:76: error: 'reachyr' was not declared in this scope; did you mean 'reachyl'?
  130 |                                 int ul=min(reachxl,reachyl),ur=max(reachxr,reachyr);
      |                                                                            ^~~~~~~
      |                                                                            reachyl