답안 #388397

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
388397 2021-04-11T10:31:22 Z cpp219 꿈 (IOI13_dreaming) C++14
컴파일 오류
0 ms 0 KB
#pragma GCC optimization "Ofast"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")

#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 1e5 + 6;
const ll lim = 3e5 + 6;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;
vector<ll> v;
vector<LL> g[N];
bool dd[N];
ll now = 1,L[N],R[N],d[N],pos[N],lens,par[N];

void DFS(ll u,ll p){
    dd[u] = 1; L[u] = R[u] = now; pos[now] = u; now++;
    for (auto i : g[u]){
        ll v = i.fs,L = i.sc;
        if (v != p) d[v] = d[u] + L,DFS(v,u),par[v] = u,R[u] = max(R[u],R[v]);
    }
}

ll farthest(ll root){
    now = 1; d[root] = 0; par[root] = -1; DFS(root,0); ll mx = -5,chosen;
    for (ll i = L[root];i <= R[root];i++){
        ll now = pos[i];
        if (mx < d[now]) chosen = now,mx = d[now];
        //cout<<now<<" "<<d[now]<<"\n";
    }
    return chosen;
}

ll Find_opt(ll now,ll total){
    ll mn = inf;
    while(now >= 0){
        ll low = total - d[now],high = d[now];
        //cout<<low<<" "<<high<<"\n";
        if (max(low,high) < mn) mn = min(mn,max(low,high));
        now = par[now];
    }
    //exit(0);
    return mn;
}

bool lf(ll x,ll y){
    return x > y;
}

int travelTime(int n, int m, int l, int A[], int B[], int T[]){
    ll ans = 0;
    for (ll i = 0;i < m;i++){
        g[A[i]].push_back({B[i],T[i]}); g[B[i]].push_back({A[i],T[i]});
    }
    for (ll i = 0;i < n;i++){
        if (!dd[i]){

            ll p = farthest(i); ll nxt = farthest(p);

            ans = max(ans,d[nxt]); v.push_back(Find_opt(nxt,d[nxt]));
        }
    }
    sort(v.begin(),v.end(),lf);
    //for (auto i : v) cout<<i<<" ";
    //exit(0);
    if (v.size() >= 2) ans = max(ans,v[0] + v[1] + L);
    if (v.size() > 2) ans = max(ans,v[1] + v[2] + 2*L);
    return ans;
}
/*
ll n,m,Len,A[N],B[N],T[N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define task "test"
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>n>>m>>Len;
    for (ll i = 0;i < m;i++) cin>>A[i]>>B[i]>>T[i];
    cout<<travelTime(n,m,Len,A,B,T);
}
*/

Compilation message

dreaming.cpp:1: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    1 | #pragma GCC optimization "Ofast"
      | 
dreaming.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:70:53: error: no matching function for call to 'max(int&, int*)'
   70 |     if (v.size() >= 2) ans = max(ans,v[0] + v[1] + L);
      |                                                     ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from dreaming.cpp:5:
/usr/include/c++/9/bits/stl_algobase.h:222:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  222 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:222:5: note:   template argument deduction/substitution failed:
dreaming.cpp:70:53: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'int*')
   70 |     if (v.size() >= 2) ans = max(ans,v[0] + v[1] + L);
      |                                                     ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from dreaming.cpp:5:
/usr/include/c++/9/bits/stl_algobase.h:268:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  268 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:268:5: note:   template argument deduction/substitution failed:
dreaming.cpp:70:53: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'int*')
   70 |     if (v.size() >= 2) ans = max(ans,v[0] + v[1] + L);
      |                                                     ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from dreaming.cpp:5:
/usr/include/c++/9/bits/stl_algo.h:3456:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3456 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
dreaming.cpp:70:53: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   70 |     if (v.size() >= 2) ans = max(ans,v[0] + v[1] + L);
      |                                                     ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from dreaming.cpp:5:
/usr/include/c++/9/bits/stl_algo.h:3462:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3462 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
dreaming.cpp:70:53: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   70 |     if (v.size() >= 2) ans = max(ans,v[0] + v[1] + L);
      |                                                     ^
dreaming.cpp:71:52: error: invalid operands of types 'int' and 'int [100006]' to binary 'operator*'
   71 |     if (v.size() > 2) ans = max(ans,v[1] + v[2] + 2*L);
      |                                                   ~^~
      |                                                   | |
      |                                                   | int [100006]
      |                                                   int