QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#116275#6659. 외곽 순환 도로 2lcjlcj#0 34ms34656kbC++205.3kb2023-06-28 12:56:082024-08-26 15:50:10

Judging History

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

  • [2024-08-26 15:50:10]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:34ms
  • 内存:34656kb
  • [2024-05-31 18:27:02]
  • 评测
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-28 12:56:08]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int maxn=1e5,intinf=1e9; 
const long long longlonginf=1e18; 

int n,K; 
long long ans; 
vector<pair<int,long long>> g[maxn+5];
long long f[maxn+5][2][2][2]; 
int dep[maxn+5],Leafpos[maxn+5],leaf; 
int Lp[maxn+5],Rp[maxn+5]; 

long long place_police(vector<int> P,vector<long long> C,vector<long long> W) {
    n=P.size()+1; 
    K=W.size();
    for (int i=0;i<n-1;i++) {
        g[P[i]].emplace_back(i+1,C[i]); 
    }
    function<void(int)> dfs0=[&](int u) {
        if (!g[u].size()) {
            Leafpos[leaf]=dep[u]&1;
            Lp[u]=leaf;
            Rp[u]=leaf++; 
        }
        else Lp[u]=intinf,Rp[u]=-intinf; 
        for (auto [v,w]:g[u]) {
            dep[v]=dep[u]+1; 
            dfs0(v); 
            Lp[u]=min(Lp[u],Lp[v]);
            Rp[u]=max(Rp[u],Rp[v]);     
        }
    } ; 
    dfs0(0); 
    assert(leaf==K); 
    for (int i=0;i<n;i++) {
        for (int o=0;o<2;o++) {
            for (int p=0;p<2;p++) {
                for (int q=0;q<2;q++) {
                    f[i][o][p][q]=longlonginf;
                }
            }
        }
    }
    auto chkmn=[&](long long &x,long long y) {
        x=min(x,y); 
    } ; 
    function<void(int)> dfs1=[&](int u) {
        if (!g[u].size()) {
            f[u][1][1][0]=0; 
            return ; 
        }
        for (auto [v,w]:g[u]) dfs1(v);
        int firv=g[u][0].first;
        long long firw=g[u][0].second; 
        for (int i=0;i<2;i++) {
            for (int j=0;j<2;j++) {
                for (int k=0;k<2;k++) {
                    if (f[firv][i][j][k]==longlonginf) continue ; 
                    chkmn(f[u][i][j][k],f[firv][i][j][k]);
                    chkmn(f[u][0][0][k],f[firv][i][j][k]+firw);  
                }
            }
        }
        int lstrp=Rp[firv]; 
        long long tmpf[2][2][2]={}; 
        for (int j=1;j<g[u].size();j++) {
            int v=g[u][j].first; long long w=g[u][j].second;   
            for (int i=0;i<2;i++) for (int j=0;j<2;j++) for (int k=0;k<2;k++) {
                tmpf[i][j][k]=longlonginf; 
            }
            for (int ul=0;ul<2;ul++) {
                for (int ur=0;ur<2;ur++) {
                    for (int vl=0;vl<2;vl++) {
                        for (int vr=0;vr<2;vr++) {
                            for (int o=0;o<2;o++) {
                                for (int p=0;p<2;p++) {
                                    for (int q=0;q<2;q++) {
                                        if (f[u][ul][ur][o]==longlonginf) continue ; 
                                        if (f[v][vl][vr][p]==longlonginf) continue ; 
                                        int nvl=vl,nvr=vr; 
                                        long long vw=0; 
                                        if (q==0) nvl=nvr=0,vw=w;
                                        for (int k=0;k<2;k++) {
                                            long long vk=0;
                                            if (k==1) vk=W[lstrp];
                                            if (ur && nvl && Leafpos[lstrp]==Leafpos[Lp[v]] && !k) continue ; 
                                            else chkmn(tmpf[ul][nvr][o|p|k],f[u][ul][ur][o]+f[v][vl][vr][p]+vw+vk); 
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            for (int i=0;i<2;i++) for (int j=0;j<2;j++) for (int k=0;k<2;k++) f[u][i][j][k]=tmpf[i][j][k];
            lstrp=Rp[v]; 
        }
        if (Lp[u]==0 && Rp[u]==K-1) {
            for (int i=0;i<2;i++) for (int j=0;j<2;j++) for (int k=0;k<2;k++) {
                tmpf[i][j][k]=longlonginf; 
            }
            for (int i=0;i<2;i++) {
                for (int j=0;j<2;j++) {
                    for (int k=0;k<2;k++) {
                        for (int o=0;o<2;o++) {
                            long long kw=0;
                            if (o==1) kw=W[K-1]; 
                            if (i && j && Leafpos[Lp[u]]==Leafpos[Rp[u]] && !o) continue ; 
                            chkmn(tmpf[i][j][k|o],f[u][i][j][k]+kw); 
                        }
                    }
                }
            }
            for (int i=0;i<2;i++) for (int j=0;j<2;j++) for (int k=0;k<2;k++) f[u][i][j][k]=tmpf[i][j][k];
            for (int i=0;i<2;i++) {
                for (int j=0;j<2;j++) {
                    for (int k=0;k<2;k++) {
                        if (K%2==1 && k==0) continue ; 
                        ans=min(ans,f[u][i][j][k]); 
                    }
                }
            }
        }
    } ; 
    ans=longlonginf; 
    dfs1(0); 
    for (int i=0;i<2;i++) {
        for (int j=0;j<2;j++) {
            for (int k=0;k<2;k++) {
                if (K%2==1 && k==0) continue ; 
                ans=min(ans,f[0][i][j][k]); 
            }
        }
    }
    return ans; 
}

/*
int main() {
    ios::sync_with_stdio(0);
    vector<int> P;
    vector<long long> C,W; 
    cin.tie(0);
    cin>>n>>K; 
    P.resize(n-1); C.resize(n-1); W.resize(K);
    for (int i=0;i<n-1;i++) cin>>P[i]; 
    for (int i=0;i<n-1;i++) cin>>C[i];  
    for (int i=0;i<K;i++) cin>>W[i]; 
    cout<<place_police(P,C,W)<<'\n'; 
    return 0;  
}
*/

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 6
Accepted
time: 0ms
memory: 3880kb

input:

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

output:

532281

result:

ok single line: '532281'

Test #2:

score: 6
Accepted
time: 1ms
memory: 3792kb

input:

6
0 581451
0 68556
0 918465
0 661406
0 41816
1000000000000 1000000000000 1000000000000 1000000000000 1000000000000

output:

1000000110372

result:

ok single line: '1000000110372'

Test #3:

score: 6
Accepted
time: 0ms
memory: 3744kb

input:

4
0 0
0 0
0 0
0 0 0

output:

0

result:

ok single line: '0'

Test #4:

score: 6
Accepted
time: 0ms
memory: 5836kb

input:

5
0 938777585449
0 576051802364
0 418735407836
0 823692221300
233950071687 338912182863 866023804654 680391493800

output:

1333076973323

result:

ok single line: '1333076973323'

Test #5:

score: 6
Accepted
time: 1ms
memory: 4080kb

input:

6
0 938777585449
0 576051802364
0 418735407836
0 823692221300
0 233950071687
338912182863 866023804654 680391493800 876313612238 476765859230

output:

991597662386

result:

ok single line: '991597662386'

Test #6:

score: 6
Accepted
time: 23ms
memory: 34656kb

input:

99995
0 573954
1 101503
2 350026
3 832411
4 311022
5 583957
6 894954
7 223392
8 287704
9 259600
10 964702
11 24863
12 831166
13 754666
14 96743
15 606341
16 198920
17 262280
18 610409
19 193417
20 192417
21 194438
22 244016
23 680809
24 106449
25 249873
26 41805
27 375383
28 927874
29 148386
30 1354...

output:

3

result:

ok single line: '3'

Test #7:

score: 6
Accepted
time: 16ms
memory: 26568kb

input:

99995
0 573954
1 101503
2 350026
3 832411
4 311022
5 583957
6 894954
7 223392
8 287704
9 259600
10 964702
11 24863
12 831166
13 754666
14 96743
15 606341
16 198920
17 262280
18 610409
19 193417
20 192417
21 194438
22 244016
23 680809
24 106449
25 249873
26 41805
27 375383
28 927874
29 148386
30 1354...

output:

0

result:

ok single line: '0'

Test #8:

score: 6
Accepted
time: 23ms
memory: 34632kb

input:

99995
0 573954
1 101503
2 350026
3 832411
4 311022
5 583957
6 894954
7 223392
8 287704
9 259600
10 964702
11 24863
12 831166
13 754666
14 96743
15 606341
16 198920
17 262280
18 610409
19 193417
20 192417
21 194438
22 244016
23 680809
24 106449
25 249873
26 41805
27 375383
28 927874
29 148386
30 1354...

output:

3

result:

ok single line: '3'

Test #9:

score: 0
Wrong Answer
time: 24ms
memory: 26668kb

input:

99995
0 573954
1 101503
2 350026
3 832411
4 311022
5 583957
6 894954
7 223392
8 287704
9 259600
10 964702
11 24863
12 831166
13 754666
14 96743
15 606341
16 198920
17 262280
18 610409
19 193417
20 192417
21 194438
22 244016
23 680809
24 106449
25 249873
26 41805
27 375383
28 927874
29 148386
30 1354...

output:

38

result:

wrong answer 1st lines differ - expected: '50', found: '38'

Subtask #2:

score: 0
Wrong Answer

Test #28:

score: 0
Wrong Answer
time: 34ms
memory: 17076kb

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:

20632254883

result:

wrong answer 1st lines differ - expected: '24980330181', found: '20632254883'

Subtask #3:

score: 0
Wrong Answer

Test #36:

score: 5
Accepted
time: 1ms
memory: 6136kb

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:

1

result:

ok single line: '1'

Test #37:

score: 0
Wrong Answer
time: 12ms
memory: 12284kb

input:

50311
0 630582
1 458618
2 300543
3 566041
4 306718
5 134260
6 736322
7 458543
8 609374
9 355623
10 706939
11 48588
12 455725
13 105118
14 71071
15 528699
16 423538
17 471781
18 98063
19 169099
20 657181
21 295537
22 49937
23 306612
24 186582
25 505763
26 831500
27 406268
28 294626
29 128111
30 42115...

output:

427455

result:

wrong answer 1st lines differ - expected: '813491', found: '427455'

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Wrong Answer

Test #77:

score: 0
Wrong Answer
time: 10ms
memory: 11788kb

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:

619471179450

result:

wrong answer 1st lines differ - expected: '939418184213', found: '619471179450'

Subtask #6:

score: 0
Skipped

Dependency #1:

0%