QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#116110#6659. 외곽 순환 도로 2hos_lyric#14 27ms14704kbC++143.4kb2023-06-28 09:49:582024-08-26 15:49:29

Judging History

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

  • [2024-08-26 15:49:29]
  • 管理员手动重测本题所有提交记录
  • 测评结果:14
  • 用时:27ms
  • 内存:14704kb
  • [2024-05-31 14:20:41]
  • 评测
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-28 09:49:58]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }


constexpr int MAX_N = 100'010;
constexpr Int INF = 1001001001001001001LL;

int N, K;
vector<int> P;
vector<Int> C, W;

vector<vector<int>> graph;
vector<int> leafs;
vector<int> ks;

Int ans;


namespace sub2 {
void run() {
  assert(K == N - 1);
  // 0: same color as root
  for (int s = 0; s < 2; ++s) {
    Int crt[2] = {INF, INF};
    crt[s] = (0 == s) ? C[0] : 0;
    for (int i = 1; i < K; ++i) {
      Int nxt[2] = {INF, INF};
      for (int x = 0; x < 2; ++x) for (int y = 0; y < 2; ++y) {
        chmin(nxt[y], crt[x] + ((x == y) ? W[i - 1] : 0) + ((0 == y) ? C[i] : 0));
      }
      copy(nxt, nxt + 2, crt);
    }
    for (int x = 0; x < 2; ++x) {
      chmin(ans, crt[x] + ((x == s) ? W[K - 1] : 0));
    }
  }
}
}  // sub2


namespace sub1 {
Int dp[MAX_N][2];
void run() {
  for (int p = 0; p < 1 << K; ++p) {
    for (int u = N; --u >= 0; ) {
      if (~ks[u]) {
        const int x = p >> ks[u] & 1;
        dp[u][x] = 0;
        dp[u][x ^ 1] = INF;
      } else {
        fill(dp[u], dp[u] + 2, 0);
        for (const int v : graph[u]) {
          for (int x = 0; x < 2; ++x) {
            Int mn = INF;
            for (int y = 0; y < 2; ++y) {
              chmin(mn, ((x == y) ? C[v - 1] : 0) + dp[v][y]);
            }
            dp[u][x] += mn;
          }
        }
      }
    }
    Int cost = min(dp[0][0], dp[0][1]);
    for (int k = 0; k < K; ++k) {
      if ((p >> k & 1) == (p >> ((k+1)%K) & 1)) {
        cost += W[k];
      }
    }
    chmin(ans, cost);
  }
}
}  // sub1


long long place_police(vector<int> P_, vector<long long> C_, vector<long long> W_) {
  P = P_;
  C = C_;
  W = W_;
  N = (int)P.size() + 1;
  K = W.size();
  
  graph.assign(N, {});
  for (int i = 0; i < N - 1; ++i) {
    graph[P[i]].push_back(i + 1);
  }
  for (int u = 1; u < N; ++u) if (graph[u].empty()) {
    leafs.push_back(u);
  }
  assert((int)leafs.size() == K);
  ks.assign(N, -1);
  for (int k = 0; k < K; ++k) {
    ks[leafs[k]] = k;
  }
  
  ans = INF;
  
#ifdef LOCAL
  if (K <= 6) {
#else
  if (K <= 5) {
#endif
    sub1::run();
  } else if (P == vector<int>(N - 1, 0)) {
    sub2::run();
  }
  return ans;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 6
Accepted

Test #1:

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

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: 0ms
memory: 4080kb

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: 3872kb

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: 3784kb

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: 0ms
memory: 3780kb

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: 14ms
memory: 14516kb

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: 11ms
memory: 14432kb

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: 13ms
memory: 14640kb

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: 6
Accepted
time: 14ms
memory: 14512kb

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:

50

result:

ok single line: '50'

Test #10:

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

input:

7
0 1
1 1
0 1
0 1
4 1
0 1
1000000000000 1000000000000 1000000000000 1000000000000

output:

0

result:

ok single line: '0'

Test #11:

score: 6
Accepted
time: 20ms
memory: 14508kb

input:

99995
0 800351
1 590567
2 404564
3 601685
4 802526
5 784654
6 558749
7 760258
8 655714
9 864130
10 678664
11 983868
12 396629
13 637742
14 592018
15 810308
16 889529
17 914966
18 623197
19 97239
20 448357
21 67877
22 785864
23 177614
24 242659
25 301722
26 5175
27 418269
28 213547
29 417295
30 80595...

output:

1000000000000

result:

ok single line: '1000000000000'

Test #12:

score: 6
Accepted
time: 27ms
memory: 14368kb

input:

99995
0 800351
1 590567
2 404564
3 601685
4 802526
5 784654
6 558749
7 760258
8 655714
9 864130
10 678664
11 983868
12 396629
13 637742
14 592018
15 810308
16 889529
17 914966
18 623197
19 97239
20 448357
21 67877
22 785864
23 177614
24 242659
25 301722
26 5175
27 418269
28 213547
29 417295
30 80595...

output:

1000000000023

result:

ok single line: '1000000000023'

Test #13:

score: 6
Accepted
time: 15ms
memory: 14456kb

input:

99995
0 800351
1 590567
2 404564
3 601685
4 802526
5 784654
6 558749
7 760258
8 655714
9 864130
10 678664
11 983868
12 396629
13 637742
14 592018
15 810308
16 889529
17 914966
18 623197
19 97239
20 448357
21 67877
22 785864
23 177614
24 242659
25 301722
26 5175
27 418269
28 213547
29 417295
30 80595...

output:

1000000000000

result:

ok single line: '1000000000000'

Test #14:

score: 6
Accepted
time: 24ms
memory: 14456kb

input:

99995
0 800351
1 590567
2 404564
3 601685
4 802526
5 784654
6 558749
7 760258
8 655714
9 864130
10 678664
11 983868
12 396629
13 637742
14 592018
15 810308
16 889529
17 914966
18 623197
19 97239
20 448357
21 67877
22 785864
23 177614
24 242659
25 301722
26 5175
27 418269
28 213547
29 417295
30 80595...

output:

1000000000023

result:

ok single line: '1000000000023'

Test #15:

score: 6
Accepted
time: 14ms
memory: 14700kb

input:

99995
0 800351
1 590567
2 404564
3 601685
4 802526
5 784654
6 558749
7 760258
8 655714
9 864130
10 678664
11 983868
12 396629
13 637742
14 592018
15 810308
16 889529
17 914966
18 623197
19 97239
20 448357
21 67877
22 785864
23 177614
24 242659
25 301722
26 5175
27 418269
28 213547
29 417295
30 80595...

output:

23

result:

ok single line: '23'

Test #16:

score: 6
Accepted
time: 9ms
memory: 14436kb

input:

99995
0 800351
1 590567
2 404564
3 601685
4 802526
5 784654
6 558749
7 760258
8 655714
9 864130
10 678664
11 983868
12 396629
13 637742
14 592018
15 810308
16 889529
17 914966
18 623197
19 97239
20 448357
21 67877
22 785864
23 177614
24 242659
25 301722
26 5175
27 418269
28 213547
29 417295
30 80595...

output:

23

result:

ok single line: '23'

Test #17:

score: 6
Accepted
time: 15ms
memory: 14508kb

input:

99995
0 307516682495
1 677180705676
2 900093321878
3 855950595166
4 60373551204
5 97525179732
6 859433105930
7 470206852651
8 836315525302
9 68512632833
10 862923859868
11 74601760822
12 219027891391
13 839738396803
14 169708425659
15 592509244955
16 824764053219
17 619446917083
18 422190804040
19 8...

output:

3249113

result:

ok single line: '3249113'

Test #18:

score: 6
Accepted
time: 18ms
memory: 14504kb

input:

99995
0 307516682495
1 677180705676
2 900093321878
3 855950595166
4 60373551204
5 97525179732
6 859433105930
7 470206852651
8 836315525302
9 68512632833
10 862923859868
11 74601760822
12 219027891391
13 839738396803
14 169708425659
15 592509244955
16 824764053219
17 619446917083
18 422190804040
19 8...

output:

484857763484

result:

ok single line: '484857763484'

Test #19:

score: 6
Accepted
time: 25ms
memory: 14464kb

input:

99995
0 307516682495
1 677180705676
2 900093321878
3 855950595166
4 60373551204
5 97525179732
6 859433105930
7 470206852651
8 836315525302
9 68512632833
10 862923859868
11 74601760822
12 219027891391
13 839738396803
14 169708425659
15 592509244955
16 824764053219
17 619446917083
18 422190804040
19 8...

output:

0

result:

ok single line: '0'

Test #20:

score: 6
Accepted
time: 18ms
memory: 14368kb

input:

99995
0 307516682495
1 677180705676
2 900093321878
3 855950595166
4 60373551204
5 97525179732
6 859433105930
7 470206852651
8 836315525302
9 68512632833
10 862923859868
11 74601760822
12 219027891391
13 839738396803
14 169708425659
15 592509244955
16 824764053219
17 619446917083
18 422190804040
19 8...

output:

86963587131

result:

ok single line: '86963587131'

Test #21:

score: 6
Accepted
time: 20ms
memory: 14472kb

input:

99995
0 307516682495
1 677180705676
2 900093321878
3 855950595166
4 60373551204
5 97525179732
6 859433105930
7 470206852651
8 836315525302
9 68512632833
10 862923859868
11 74601760822
12 219027891391
13 839738396803
14 169708425659
15 592509244955
16 824764053219
17 619446917083
18 422190804040
19 8...

output:

3249113

result:

ok single line: '3249113'

Test #22:

score: 6
Accepted
time: 17ms
memory: 14704kb

input:

99995
0 307516682495
1 677180705676
2 900093321878
3 855950595166
4 60373551204
5 97525179732
6 859433105930
7 470206852651
8 836315525302
9 68512632833
10 862923859868
11 74601760822
12 219027891391
13 839738396803
14 169708425659
15 592509244955
16 824764053219
17 619446917083
18 422190804040
19 8...

output:

484861012597

result:

ok single line: '484861012597'

Test #23:

score: 6
Accepted
time: 19ms
memory: 14508kb

input:

99995
0 307516682495
1 677180705676
2 900093321878
3 855950595166
4 60373551204
5 97525179732
6 859433105930
7 470206852651
8 836315525302
9 68512632833
10 862923859868
11 74601760822
12 219027891391
13 839738396803
14 169708425659
15 592509244955
16 824764053219
17 619446917083
18 422190804040
19 8...

output:

72033520

result:

ok single line: '72033520'

Test #24:

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

input:

99995
0 307516682495
1 677180705676
2 900093321878
3 855950595166
4 60373551204
5 97525179732
6 859433105930
7 470206852651
8 836315525302
9 68512632833
10 862923859868
11 74601760822
12 219027891391
13 839738396803
14 169708425659
15 592509244955
16 824764053219
17 619446917083
18 422190804040
19 8...

output:

87023183814

result:

ok single line: '87023183814'

Test #25:

score: 6
Accepted
time: 17ms
memory: 14532kb

input:

99995
0 307516682495
1 677180705676
2 900093321878
3 855950595166
4 60373551204
5 97525179732
6 859433105930
7 470206852651
8 836315525302
9 68512632833
10 862923859868
11 74601760822
12 219027891391
13 839738396803
14 169708425659
15 592509244955
16 824764053219
17 619446917083
18 422190804040
19 8...

output:

3249113

result:

ok single line: '3249113'

Test #26:

score: 6
Accepted
time: 18ms
memory: 14704kb

input:

99995
0 307516682495
1 677180705676
2 900093321878
3 855950595166
4 60373551204
5 97525179732
6 859433105930
7 470206852651
8 836315525302
9 68512632833
10 862923859868
11 74601760822
12 219027891391
13 839738396803
14 169708425659
15 592509244955
16 824764053219
17 619446917083
18 422190804040
19 8...

output:

3249113

result:

ok single line: '3249113'

Test #27:

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

input:

4
0 9
0 8
0 0
9 9 9

output:

9

result:

ok single line: '9'

Subtask #2:

score: 8
Accepted

Test #28:

score: 8
Accepted
time: 23ms
memory: 13384kb

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:

24980330181

result:

ok single line: '24980330181'

Test #29:

score: 8
Accepted
time: 18ms
memory: 13368kb

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:

24980330181

result:

ok single line: '24980330181'

Test #30:

score: 8
Accepted
time: 19ms
memory: 13664kb

input:

99998
0 792854
0 622829
0 836127
0 847372
0 71732
0 241096
0 487224
0 696890
0 899047
0 845614
0 27226
0 270985
0 698890
0 64699
0 856738
0 685434
0 766150
0 540443
0 802763
0 874879
0 250532
0 834015
0 616087
0 771638
0 262098
0 458015
0 959723
0 408130
0 880649
0 456673
0 923653
0 969100
0 439032
...

output:

1025006589524

result:

ok single line: '1025006589524'

Test #31:

score: 8
Accepted
time: 16ms
memory: 13464kb

input:

99998
0 792854
0 622829
0 836127
0 847372
0 71732
0 241096
0 487224
0 696890
0 899047
0 845614
0 27226
0 270985
0 698890
0 64699
0 856738
0 685434
0 766150
0 540443
0 802763
0 874879
0 250532
0 834015
0 616087
0 771638
0 262098
0 458015
0 959723
0 408130
0 880649
0 456673
0 923653
0 969100
0 439032
...

output:

1025006589524

result:

ok single line: '1025006589524'

Test #32:

score: 8
Accepted
time: 25ms
memory: 13424kb

input:

99997
0 111160315429
0 355167263283
0 846519401525
0 697515481745
0 653176944193
0 975281743723
0 947695822588
0 443385029699
0 86490619914
0 542182758068
0 140914234365
0 453333219458
0 484226894553
0 930883160414
0 961277575066
0 392480084360
0 638524603170
0 806648354769
0 552428035490
0 99450464...

output:

18302944415585093

result:

ok single line: '18302944415585093'

Test #33:

score: 8
Accepted
time: 21ms
memory: 13416kb

input:

99998
0 111160315429
0 355167263283
0 846519401525
0 697515481745
0 653176944193
0 975281743723
0 947695822588
0 443385029699
0 86490619914
0 542182758068
0 140914234365
0 453333219458
0 484226894553
0 930883160414
0 961277575066
0 392480084360
0 638524603170
0 806648354769
0 552428035490
0 99450464...

output:

18289278171456444

result:

ok single line: '18289278171456444'

Test #34:

score: 8
Accepted
time: 20ms
memory: 13372kb

input:

99997
0 111160315429
0 355167263283
0 846519401525
0 697515481745
0 653176944193
0 975281743723
0 947695822588
0 443385029699
0 86490619914
0 542182758068
0 140914234365
0 453333219458
0 484226894553
0 930883160414
0 961277575066
0 392480084360
0 638524603170
0 806648354769
0 552428035490
0 99450464...

output:

18302944415585093

result:

ok single line: '18302944415585093'

Test #35:

score: 8
Accepted
time: 25ms
memory: 13540kb

input:

99998
0 111160315429
0 355167263283
0 846519401525
0 697515481745
0 653176944193
0 975281743723
0 947695822588
0 443385029699
0 86490619914
0 542182758068
0 140914234365
0 453333219458
0 484226894553
0 930883160414
0 961277575066
0 392480084360
0 638524603170
0 806648354769
0 552428035490
0 99450464...

output:

18289278171456444

result:

ok single line: '18289278171456444'

Subtask #3:

score: 0
Wrong Answer

Test #36:

score: 0
Wrong Answer
time: 0ms
memory: 3800kb

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:

1001001001001001001

result:

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

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Wrong Answer

Test #77:

score: 0
Wrong Answer
time: 4ms
memory: 8452kb

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:

1001001001001001001

result:

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

Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

0%