QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#407122#6659. 외곽 순환 도로 2duongnc0000 0ms0kbC++205.4kb2024-05-07 23:20:242024-08-26 15:53:07

Judging History

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

  • [2024-08-26 15:53:07]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-05-07 23:20:26]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-05-07 23:20:24]
  • 提交

answer

#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define i64 long long
#define pb push_back
#define ff first
#define ss second
#define isz(x) (int)x.size()
using namespace std;

template<class T>
struct graph{
    using Weight_t = T;
    struct Edge_t{
        int from, to;
        T cost;
    };
    int n;
    vector<Edge_t> edge;
    vector<vector<int>> adj;
    function<bool(int)> ignore;
    graph(int n = 1): n(n), adj(n){
        assert(n >= 1);
    }
    graph(const vector<vector<int>> &adj, bool undirected = true): n((int)adj.size()), adj(n){
        assert(n >= 1);
        if(undirected){
            for(auto u = 0; u < n; ++ u) for(auto v: adj[u]) if(u < v) link(u, v);
        }
        else for(auto u = 0; u < n; ++ u) for(auto v: adj[u]) orient(u, v);
    }
    graph(const vector<vector<pair<int, T>>> &adj, bool undirected = true): n((int)adj.size()), adj(n){
        assert(n >= 1);
        if(undirected){
            for(auto u = 0; u < n; ++ u) for(auto [v, w]: adj[u]) if(u < v) link(u, v, w);
        }
        else for(auto u = 0; u < n; ++ u) for(auto [v, w]: adj[u]) orient(u, v, w);
    }
    graph(int n, vector<array<int, 2>> &edge, bool undirected = true): n(n), adj(n){
        assert(n >= 1);
        for(auto [u, v]: edge) undirected ? link(u, v) : orient(u, v);
    }
    graph(int n, vector<tuple<int, int, T>> &edge, bool undirected = true): n(n), adj(n){
        assert(n >= 1);
        for(auto [u, v, w]: edge) undirected ? link(u, v, w) : orient(u, v, w);
    }
    int operator()(int u, int id) const{
        #ifdef LOCAL
        assert(0 <= id && id < (int)edge.size());
        assert(edge[id].from == u || edge[id].to == u);
        #endif
        return u ^ edge[id].from ^ edge[id].to;
    }
    int link(int u, int v, T w = {}){ // insert an undirected edge
        int id = (int)edge.size();
        adj[u].push_back(id), adj[v].push_back(id), edge.push_back({u, v, w});
        return id;
    }
    int orient(int u, int v, T w = {}){ // insert a directed edge
        int id = (int)edge.size();
        adj[u].push_back(id), edge.push_back({u, v, w});
        return id;
    }
    void clear(){
        for(auto [u, v, w]: edge){
            adj[u].clear();
            adj[v].clear();
        }
        edge.clear();
        ignore = {};
    }
    graph transpose() const{ // the transpose of the directed graph
        graph res(n);
        for(auto id = 0; id < (int)edge.size(); ++ id){
            if(ignore && ignore(id)) continue;
            res.orient(edge[id].to, edge[id].from, edge[id].cost);
        }
        return res;
    }
    int degree(int u) const{ // the degree (outdegree if directed) of u (without the ignoration rule)
        return (int)adj[u].size();
    }
    // The adjacency list is sorted for each vertex.
    vector<vector<int>> get_adjacency_list() const{
        vector<vector<int>> res(n);
        for(auto u = 0; u < n; ++ u) for(auto id: adj[u]){
            if(ignore && ignore(id)) continue;
            res[(*this)(u, id)].push_back(u);
        }
        return res;
    }
    void set_ignoration_rule(const function<bool(int)> &f){
        ignore = f;
    }
    void reset_ignoration_rule(){
        ignore = nullptr;
    }
    friend ostream &operator<<(ostream &out, const graph &g){
        for(auto id = 0; id < (int)g.edge.size(); ++ id){
            if(g.ignore && g.ignore(id)) continue;
            auto &e = g.edge[id];
            out << "{" << e.from << ", " << e.to << ", " << e.cost << "}\n";
        }
        return out;
    }
};

#define vi vector<i64>
#define vii vector<vi>
#define viii vector<vii>
#define viiii vector<viii>

const i64 oo = 1e18;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define chkmin(a, b) a = (a < b ? a : b)

i64 place_police(vector<int> P, vector<i64> C, vector<i64> W) {
    int n = isz(P);
    graph<i64> g(n + 1);
    for (int i = 0; i < n; ++i) g.orient(P[i], i + 1, C[i]);

    int ptr = 0;
    viiii dp(n + 1, viii(2, vii(2, vi(2, oo))));
    auto dfs = [&](auto self, int u, int _pe) -> void {
        if (g.adj[u].empty()) {
            ++ptr;
            for (int i = 0; i < 2; ++i) dp[u][i][i][i] = 0;
            return;
        }

        int cc = 0;
        i64 cw = W[ptr];
        for (auto id : g.adj[u]) {
            if (id == _pe) continue;
            int v = g.edge[id].to;
            self(self, v, id);

            viii ndp(2, vii(2, vi(2, oo)));
            if (!cc) {
                FOR(col, 0, 2) FOR(ccol, 0, 2) FOR(lcol, 0, 2) FOR(rcol, 0, 2) {
                    chkmin(ndp[col][lcol][rcol], dp[v][ccol][lcol][rcol] + (col == ccol ? g.edge[id].cost : 0));
                }
            }
            else {
                FOR(col, 0, 2) FOR(ccol, 0, 2) FOR(lcol1, 0, 2) FOR(rcol1, 0, 2) FOR(lcol2, 0, 2) FOR(rcol2, 0, 2) {
                    chkmin(ndp[col][lcol1][rcol2], dp[u][col][lcol1][rcol1] + dp[v][ccol][lcol2][rcol2] + (col == ccol ? g.edge[id].cost : 0) + (rcol1 == lcol2 ? cw : 0));
                }
            }

            ++cc, cw = W[ptr], dp[u] = ndp;
        }
    };
    dfs(dfs, 0, -1);

    assert(ptr + 1 == isz(W));

    i64 res = oo;
    FOR(col, 0, 2) FOR(lcol, 0, 2) FOR(rcol, 0, 2) {
        res = min(res, dp[0][col][lcol][rcol] + (lcol == rcol ? W[ptr] : 0));
    }

    return res;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

5
0 452912
0 820899
0 79369
0 232463
1000000000000 1000000000000 1000000000000 1000000000000

output:

Unauthorized output

result:


Subtask #2:

score: 0
Runtime Error

Test #28:

score: 0
Runtime Error

input:

99997
0 122727
0 267270
0 846212
0 454122
0 805668
0 614161
0 7805
0 173284
0 684707
0 269129
0 930945
0 1101
0 992427
0 297412
0 759787
0 227130
0 120418
0 90914
0 333684
0 46144
0 519912
0 171490
0 823586
0 121787
0 674177
0 560254
0 753090
0 853359
0 465464
0 655527
0 631303
0 919012
0 597126
0 1...

output:

Unauthorized output

result:


Subtask #3:

score: 0
Runtime Error

Test #36:

score: 0
Runtime Error

input:

11
0 9
0 8
2 0
3 7
3 1
2 6
0 0
7 7
7 1
9 6
1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000

output:

Unauthorized output

result:


Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Runtime Error

Test #77:

score: 0
Runtime Error

input:

50311
0 962897543825
1 887020369743
2 363658802934
3 481009844166
4 1099712574
5 858320882162
6 521927434762
7 379344260539
8 73024776148
9 634183458545
10 869560347910
11 81581323331
12 750044298516
13 307013017409
14 306226274039
15 423923546601
16 482114694167
17 849292461119
18 299993045938
19 7...

output:

Unauthorized output

result:


Subtask #6:

score: 0
Skipped

Dependency #1:

0%