제출 #363805

#제출 시각아이디문제언어결과실행 시간메모리
363805David_M경주 (Race) (IOI11_race)C++17
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N=200005;
int sz[N], e[N], z1[N], z2[N], o, k, K, Ans=N;
vector <pair<int, int> > v[N];
gp_hash_table<int, int, chash> m[N];

void solve(int x=0, int pa=0){
	
	sz[x]=1;
	int mx=0, Y, D;
	
	for (auto [y,d]:v[x]){
		if(y==pa)continue;
		solve(y, x);
		sz[x]+=sz[y];
		if(sz[y]>mx) mx=sz[y], Y=y, D=d;
	}
	
	if(sz[x]==1) e[x]=o++;
	else z1[x]=z1[Y]+D, z2[x]=z2[Y]+1, e[x]=e[Y];
	m[e[x]][0-z1[x]]=0-z2[x];
	
	for (auto [y,d]:v[x]){
		if(y==pa||y==Y)continue;
		for(auto [kk,ans]:m[e[y]]){
			k=kk+d+z1[y]+z1[x];
			ans+=1+z2[y]+z2[x];
			if(m[e[x]].find(K-k)!=m[e[x]].end()) Ans=min(Ans, ans+m[e[x]][K-k]);
		}
		for(auto [kk,ans]:m[e[y]]){
			k=kk+d+z1[y]-z1[x];
			ans+=1+z2[y]-z2[x];
			if(m[e[x]].find(k)==m[e[x]].end() || m[e[x]][k]>ans) m[e[x]][k]=ans;
		}
	}
	if(m[e[x]].find(K-z1[x])!=m[e[x]].end())Ans=min(Ans,z2[x]+m[e[x]][K-z1[x]]);
}
 
int best_path(int n, int k, int H[][2], int L[]){
	K=k;
	for (int i=0; i<n-1; i++)
		v[H[i][0]].push_back({H[i][1],L[i]}),
		v[H[i][1]].push_back({H[i][0],L[i]});
	
	solve();
	
	return (Ans==N)?-1:Ans;
}

컴파일 시 표준 에러 (stderr) 메시지

race.cpp:23:25: error: 'chash' was not declared in this scope
   23 | gp_hash_table<int, int, chash> m[N];
      |                         ^~~~~
race.cpp:23:30: error: template argument 3 is invalid
   23 | gp_hash_table<int, int, chash> m[N];
      |                              ^
race.cpp: In function 'void solve(int, int)':
race.cpp:39:17: error: invalid types 'int[int]' for array subscript
   39 |  m[e[x]][0-z1[x]]=0-z2[x];
      |                 ^
race.cpp:43:27: error: 'begin' was not declared in this scope
   43 |   for(auto [kk,ans]:m[e[y]]){
      |                           ^
race.cpp:43:27: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:95,
                 from race.cpp:1:
/usr/include/c++/9/valarray:1224:5: note:   'std::begin'
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
In file included from /usr/include/c++/9/filesystem:38,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:129,
                 from race.cpp:1:
/usr/include/c++/9/bits/fs_dir.h:516:3: note:   'std::filesystem::__cxx11::begin'
  516 |   begin(recursive_directory_iterator __iter) noexcept
      |   ^~~~~
race.cpp:43:27: error: 'end' was not declared in this scope
   43 |   for(auto [kk,ans]:m[e[y]]){
      |                           ^
race.cpp:43:27: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:95,
                 from race.cpp:1:
/usr/include/c++/9/valarray:1244:5: note:   'std::end'
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
In file included from /usr/include/c++/9/filesystem:38,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:129,
                 from race.cpp:1:
/usr/include/c++/9/bits/fs_dir.h:520:3: note:   'std::filesystem::__cxx11::end'
  520 |   end(recursive_directory_iterator) noexcept
      |   ^~~
race.cpp:46:15: error: request for member 'find' in 'm[e[x]]', which is of non-class type 'int'
   46 |    if(m[e[x]].find(K-k)!=m[e[x]].end()) Ans=min(Ans, ans+m[e[x]][K-k]);
      |               ^~~~
race.cpp:46:34: error: request for member 'end' in 'm[e[x]]', which is of non-class type 'int'
   46 |    if(m[e[x]].find(K-k)!=m[e[x]].end()) Ans=min(Ans, ans+m[e[x]][K-k]);
      |                                  ^~~
race.cpp:46:69: error: invalid types 'int[int]' for array subscript
   46 |    if(m[e[x]].find(K-k)!=m[e[x]].end()) Ans=min(Ans, ans+m[e[x]][K-k]);
      |                                                                     ^
race.cpp:48:27: error: 'begin' was not declared in this scope
   48 |   for(auto [kk,ans]:m[e[y]]){
      |                           ^
race.cpp:48:27: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:95,
                 from race.cpp:1:
/usr/include/c++/9/valarray:1224:5: note:   'std::begin'
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
In file included from /usr/include/c++/9/filesystem:38,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:129,
                 from race.cpp:1:
/usr/include/c++/9/bits/fs_dir.h:516:3: note:   'std::filesystem::__cxx11::begin'
  516 |   begin(recursive_directory_iterator __iter) noexcept
      |   ^~~~~
race.cpp:48:27: error: 'end' was not declared in this scope
   48 |   for(auto [kk,ans]:m[e[y]]){
      |                           ^
race.cpp:48:27: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:95,
                 from race.cpp:1:
/usr/include/c++/9/valarray:1244:5: note:   'std::end'
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
In file included from /usr/include/c++/9/filesystem:38,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:129,
                 from race.cpp:1:
/usr/include/c++/9/bits/fs_dir.h:520:3: note:   'std::filesystem::__cxx11::end'
  520 |   end(recursive_directory_iterator) noexcept
      |   ^~~
race.cpp:51:15: error: request for member 'find' in 'm[e[x]]', which is of non-class type 'int'
   51 |    if(m[e[x]].find(k)==m[e[x]].end() || m[e[x]][k]>ans) m[e[x]][k]=ans;
      |               ^~~~
race.cpp:51:32: error: request for member 'end' in 'm[e[x]]', which is of non-class type 'int'
   51 |    if(m[e[x]].find(k)==m[e[x]].end() || m[e[x]][k]>ans) m[e[x]][k]=ans;
      |                                ^~~
race.cpp:51:50: error: invalid types 'int[int]' for array subscript
   51 |    if(m[e[x]].find(k)==m[e[x]].end() || m[e[x]][k]>ans) m[e[x]][k]=ans;
      |                                                  ^
race.cpp:51:66: error: invalid types 'int[int]' for array subscript
   51 |    if(m[e[x]].find(k)==m[e[x]].end() || m[e[x]][k]>ans) m[e[x]][k]=ans;
      |                                                                  ^
race.cpp:54:13: error: request for member 'find' in 'm[e[x]]', which is of non-class type 'int'
   54 |  if(m[e[x]].find(K-z1[x])!=m[e[x]].end())Ans=min(Ans,z2[x]+m[e[x]][K-z1[x]]);
      |             ^~~~
race.cpp:54:36: error: request for member 'end' in 'm[e[x]]', which is of non-class type 'int'
   54 |  if(m[e[x]].find(K-z1[x])!=m[e[x]].end())Ans=min(Ans,z2[x]+m[e[x]][K-z1[x]]);
      |                                    ^~~
race.cpp:54:75: error: invalid types 'int[int]' for array subscript
   54 |  if(m[e[x]].find(K-z1[x])!=m[e[x]].end())Ans=min(Ans,z2[x]+m[e[x]][K-z1[x]]);
      |                                                                           ^