QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#150549#6660. 택시 여행penguinman0 1ms3732kbC++176.3kb2023-08-25 20:26:052023-08-25 20:26:06

Judging History

你现在查看的是最新测评结果

  • [2023-08-25 20:26:06]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3732kb
  • [2023-08-25 20:26:05]
  • 提交

answer

#include <bits/stdc++.h>


using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::string;
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 pb emplace_back
#define mp std::make_pair
#define mtp std::make_tuple
#define all(a) a.begin(),a.end()

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


std::vector<long long> travel(std::vector<long long> A,
        std::vector<int> B, std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
    ll N = A.size();
    vii edge(N), weight(N), d_edge(N);
    rep(i,0,N-1){
        edge[U[i]].pb(V[i]);
        edge[V[i]].pb(U[i]);
        weight[U[i]].pb(W[i]);
        weight[V[i]].pb(W[i]);
    }
    vi dist(N, -1), par(N), hld_dist(N);
    {
        std::queue<ll> que;
        vector<bool> visited(N);
        dist[0] = 0;
        que.push(0);
        while(!que.empty()){
            ll now = que.front(); que.pop();
            rep(i,0,edge[now].size()){
                ll next = edge[now][i];
                if(dist[next] != -1) continue;
                dist[next] = dist[now]+weight[now][i];
                que.push(next);
                d_edge[now].pb(next);
                hld_dist[next] = hld_dist[now]+1;
            }
        }
    }
    vi c_par(N,-1);
    vector<bool> dead(N);

    vi subtree(N);

    std::function<void(ll)> calc_subtree = [&](ll now){
        subtree[now] = 1;
        for(auto next: d_edge[now]){
            if(dead[next]) continue;
            calc_subtree(next);
            subtree[now] += subtree[next];
        }
    };

    // hld

    vi hld_par(N);

    std::function<void(ll)> heavy_light_decomposition = [&](ll now){
        rep(i,1,d_edge[now].size()){
            if(subtree[edge[now][0]] < subtree[edge[now][i]]) std::swap(edge[now][i], edge[now][0]);
        }
        rep(i,0,d_edge[now].size()){
            ll next = d_edge[now][i];
            if(i) hld_par[next] = next;
            else hld_par[next] = hld_par[now];
            par[next] = now;
            heavy_light_decomposition(next);
        }
    };

    auto LCA = [&](ll l, ll r){
        while(true){
            if(hld_par[l] == hld_par[r]){
                if(hld_dist[l] < hld_dist[r]) std::swap(l,r);
                return r;
            }
            if(hld_dist[hld_par[l]] < hld_dist[hld_par[r]]) std::swap(l,r);
            l = hld_par[hld_dist[l]];
        }
    };

    auto distance = [&](ll l, ll r){
        return dist[l]+dist[r]-2*dist[LCA(l,r)];
    };

    calc_subtree(0);
    heavy_light_decomposition(0);

    // centroid tree
    
    std::function<ll(ll, ll)> find_centroid = [&](ll root, ll now){
        ll max = subtree[root]-subtree[now];
        for(auto next: d_edge[now]){
            if(dead[next]) continue;
            ll c = find_centroid(root, next);
            if(c != -1) return c;
            max = std::max(max, subtree[next]);
        }
        if(max*2 <= subtree[root]) return now;
        return ll(-1);
    };
    std::function<void(ll,ll)> centroid_coloring = [&](ll centroid, ll now){
        if(now != centroid) c_par[now] = centroid;
        for(auto next: d_edge[now]){
            if(dead[next]) continue;
            centroid_coloring(centroid, next);
        }
    };

    std::function<void(ll)> dfs_centroid_decomposition = [&](ll root){
        if(dead[root]) return;
        calc_subtree(root);
        if(subtree[root] == 1) return;
        ll c = find_centroid(root,root);
        centroid_coloring(c, root);
        dead[c] = true;
        for(auto next: d_edge[c]){
            dfs_centroid_decomposition(next);
        }
        dfs_centroid_decomposition(root);
    };

    dfs_centroid_decomposition(0);

    vector<pii> data(N);
    rep(i,0,N) data[i] = mp(B[i], i);
    sort(all(data));
    reverse(all(data));

    vector<vector<pii>> lines(N);

    // m について判定
    // is_need : true → m は必要
    auto is_need = [&](pii l, pii m, pii r){
        return true;
        return ((r.second-m.second)*(m.first-l.first) >= (m.second-l.second)*(r.first-m.first));
    };

    auto add_line = [&](ll idx, pii l){
        /*if(!lines[idx].empty() && lines[idx].back().first == l.first){
            ll n = lines[idx].size();
            if(lines[idx][n-1].second <= l.second) return;
            lines[idx].pop_back();
        }*/

        while(lines[idx].size() > 1){
            ll n = lines[idx].size();
            if(!is_need(lines[idx][n-2], lines[idx][n-1], l)) lines[idx].pop_back();
            else break;
        }

        lines[idx].pb(l);
    };

    auto value = [&](pii f, ll x){
        return f.first*x+f.second;
    };

    auto calc = [&](ll idx, ll x){
        if(lines[idx].empty()) return inf;
        {
            ll min = inf;
            for(auto el: lines[idx]){
                min = std::min(min, value(el, x));
                //cout << value(el, x) << " ";
            }
            //cout << endl;
            return min;
        }
        ll left = 0, right = lines[idx].size();
        while(left+1 < right){
            ll mid = (left+right)/2;
            if(value(lines[idx][mid-1],x) > value(lines[idx][mid], x)) left = mid;
            else right = mid;
        }
        return value(lines[idx][left], x);
    };

    vi ans(N, inf);
    ans[0] = 0;

    for(auto el: data){
        ll now = el.second;
        ll n_v = now;
        while(true){
            ans[now] = std::min(ans[now], calc(n_v, distance(now, n_v)));
            if(c_par[n_v] == -1) break;
            n_v = c_par[n_v];
        }
        n_v = now;
        while(true){
            add_line(n_v, mp(B[now], A[now]+ans[now]+distance(now, n_v)*B[now]));
            if(c_par[n_v] == -1) break;
            n_v = c_par[n_v];
        }
    }
    rep(now,0,N){
        ll n_v = now;
        while(true){
            ans[now] = std::min(ans[now], calc(n_v, distance(now, n_v)));
            if(c_par[n_v] == -1) break;
            n_v = c_par[n_v];
        }
    }
    {
        reverse(all(ans));
        ans.pop_back();
        reverse(all(ans));
    }
    return ans;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 7
Accepted
time: 1ms
memory: 3636kb

input:

2
684124582850 713748627948
74361 256955
0 1 661088

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
733283747618
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 3732kb

input:

3
251115773325 363097865287 358609487841
826785 213106 914768
0 1 851938
2 0 231697

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
955485332655
442679377470
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

ok 4 lines

Test #3:

score: 0
Accepted
time: 1ms
memory: 3724kb

input:

3
489998888627 318672977903 70353752652
258347 458793 258657
2 1 156120
0 2 524840

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
665922861747
625589728107
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

ok 4 lines

Test #4:

score: 0
Accepted
time: 0ms
memory: 3664kb

input:

3
737471938521 315388610250 818943569900
726908 666797 564862
0 1 460302
0 2 785280

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
1072069144737
1308298252761
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

ok 4 lines

Test #5:

score: 0
Accepted
time: 1ms
memory: 3648kb

input:

4
201836820267 208957719162 992553400562 566050337171
243994 65303 590123 936951
1 0 259719
0 3 860376
3 2 513584

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
265206697953
537074816507
411763402011
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

ok 5 lines

Test #6:

score: 0
Accepted
time: 1ms
memory: 3664kb

input:

4
440719935569 160237864481 704297665373 767778991240
451998 371509 46564 828427
1 0 861960
1 3 830699
2 3 185693

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
830324131649
1289731282865
1205798418251
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

ok 5 lines

Test #7:

score: -7
Wrong Answer
time: 1ms
memory: 3672kb

input:

5
148262899914 9382086008 622202345986 443806901161 213829280326
178155 503016 333953 572340 461148
0 3 453941
3 2 84057
4 0 171136
3 1 598794

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
497556621549
244109933604
229134758769
178751633994
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

wrong answer 2nd lines differ - expected: '335812903839', found: '497556621549'

Subtask #2:

score: 0
Time Limit Exceeded

Test #31:

score: 0
Time Limit Exceeded

input:

100000
746699125678 374834842799 250803643493 620187038832 454433387570 406226564003 897157438699 99473514061 734784419618 503968957100 363935477037 277126009840 52078020050 990757079812 847235285349 950784717285 271017141367 861087225700 996035427219 520682200664 282013988419 415183977876 882007771...

output:

Unauthorized output

result:


Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Time Limit Exceeded

Test #69:

score: 0
Time Limit Exceeded

input:

100000
15175010 23519365 21177669 27079342 9089 16784452 29693960 23124925 17048604 10179491 12828214 24992902 8483134 2928073 23807522 7332137 17421520 28460746 1607282 13224363 11900728 11794692 11495061 4687109 23460275 7657982 27417256 16978162 7326803 23083826 24942987 16610314 12147303 2828271...

output:

Unauthorized output

result:


Subtask #5:

score: 0
Time Limit Exceeded

Test #94:

score: 0
Time Limit Exceeded

input:

99281
551670361798 568902251563 418071776626 697635341894 641578820039 117221079324 812766431051 425410617978 663769685693 282144284527 799662290178 749088952784 586626406385 122473825417 459510657357 871705247919 443707710712 735612808044 237919555727 829939639783 122127143240 616906466299 24431898...

output:

Unauthorized output

result:


Subtask #6:

score: 0
Skipped

Dependency #1:

0%