QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#141460#6659. 외곽 순환 도로 2penguinman#Compile Error//C++174.0kb2023-08-17 14:03:502024-07-04 01:46:39

Judging History

你现在查看的是测评时间为 2024-07-04 01:46:39 的历史记录

  • [2024-08-26 15:51:12]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:28ms
  • 内存:27144kb
  • [2024-07-04 01:46:39]
  • 评测
  • [2023-08-17 14:03:50]
  • 提交

answer

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using pii = std::pair<ll,ll>;

#define rep(i,j,k) for(ll i=ll(j); i<ll(k); i++)
#define REP(i,j,k) for(ll i=ll(j); i<=ll(k); i++)
#define per(i,j,k) for(ll i=ll(j); i>=ll(k); i--)
#define ln "\n"
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define mp std::make_pair
#define mtp std::make_tuple

constexpr ll inf = (1ll<<60);

struct union_find{
    ll N;
    vi par, sz;
    union_find(ll n): N(n){
        par.resize(N);
        sz.resize(N,1);
        rep(i,0,N) par[i] = i;
    }
    ll root(ll now){
        if(par[now] == now) return now;
        return par[now] = root(par[now]);
    }
    void merge(ll u, ll v){
        u = root(u);
        v = root(v);
        if(u == v) return;
        if(sz[u] > sz[v]) std::swap(u,v);
        sz[v] += sz[u];
        sz[u] = 0;
        par[u] = v;
    }
    bool same(ll u, ll v){
        return root(u) == root(v);
    }
};

long long place_police(vector<int> P, vector<long long> C, vector<long long> W){
    ll N = P.size()+1;
    vii edge(N), weight(N);
    vi par(N,-1), wpar(N,inf);
    rep(i,1,N){
        edge[P[i-1]].pb(i);
        weight[P[i-1]].pb(C[i-1]);
        par[i] = P[i-1];
        wpar[i] = C[i-1];
    }
    vi ord;
    vi left(N), right(N);
    std::function<void(ll)> dfs = [&](ll now){
        left[now] = ord.size();
        ord.pb(now);
        for(auto next: edge[now]){
            dfs(next);
        }
        right[now] = ord.size();
        ord.pb(now);
    };
    dfs(0);
    ll K = W.size();
    vi V;
    rep(i,0,N){
        if(left[i] == right[i]-1) V.pb(i);
    }
    assert(V.size() == K);
    vi ml(K), mr(K), mm(K);
    rep(i,0,K){
        ml[i] = mr[i] = inf;
        mm[i] = W[i];
        ll dist = 0;
        {
            ll now = V[i];
            ll idx = right[now];
            while(true){
                ml[i] = std::min(ml[i], wpar[now]);
                dist++;
                if(ord[idx+1] != par[now]) break;
                idx++;
                now = par[now];
            }
        }
        {
            ll now = V[(i+1)%K];
            ll idx = left[now];
            while(true){
                dist++;
                mr[i] = std::min(mr[i], wpar[now]);
                if(ord[idx-1] != par[now]) break;
                idx--;
                now = par[now];
            }
        }
        if(dist%2) mm[i] = 0;
        //cout << ml[i] << " " << mr[i] << " " << mm[i] << ln;
    }
    ll ans = inf;
    {
        vii dp(K+1, vi(2,inf));
        dp[0][0] = 0;
        rep(i,0,K){
            dp[i+1][0] = dp[i][0]+std::min({ml[i], mr[i]});
            dp[i+1][1] = dp[i][1]+std::min({ml[i], mr[i], mm[i]});
            dp[i+1][1] = std::min(dp[i+1][1], dp[i][0]+mm[i]);
            if(i > 0){
                dp[i+1][1] = std::min(dp[i+1][1], dp[i-1][1]+std::max(mr[i-1], ml[i]));
                dp[i+1][0] = std::min(dp[i+1][0], dp[i-1][0]+std::max(mr[i-1], ml[i]));
            }
        }
        ans = std::min(ans, dp[K][1]);
    }
    {
        {
            vi ML(K), MR(K), MM(K);
            rep(i,0,K){
                ML[i] = ml[(i+K-1)%K];
                MR[i] = mr[(i+K-1)%K];
                MM[i] = mm[(i+K-1)%K];
            }
            ml = ML, mr = MR, mm = MM;
        }
        vii dp(K+1, vi(2,inf));
        dp[0][0] = 0;
        rep(i,0,K){
            dp[i+1][0] = dp[i][0]+std::min({ml[i], mr[i]});
            dp[i+1][1] = dp[i][1]+std::min({ml[i], mr[i], mm[i]});
            dp[i+1][1] = std::min(dp[i+1][1], dp[i][0]+mm[i]);
            if(i > 0){
                dp[i+1][1] = std::min(dp[i+1][1], dp[i-1][1]+std::max(mr[i-1], ml[i]));
                dp[i+1][0] = std::min(dp[i+1][0], dp[i-1][0]+std::max(mr[i-1], ml[i]));
            }
        }
        ans = std::min(ans, dp[K][1]);
    }
    return ans;
}


详细

cc1plus: fatal error: implementer.cpp: No such file or directory
compilation terminated.