QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#406842#6659. 외곽 순환 도로 2nguyentunglam0 18ms18452kbC++173.4kb2024-05-07 19:10:292024-08-26 15:52:39

Judging History

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

  • [2024-08-26 15:52:39]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:18ms
  • 内存:18452kb
  • [2024-05-07 19:10:43]
  • 评测
  • 测评结果:0
  • 用时:22ms
  • 内存:18664kb
  • [2024-05-07 19:10:29]
  • 提交

answer

#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;

const int N = 1e5 + 10;

long long f[2][2][2][N];

long long g[2][2][2];

int adj_leaf[N];

int cnt, ed[N];

vector<pair<int, long long> > adj[N];

void dfs(int u) {
  if (adj[u].size() == 0) {
    ed[u] = ++cnt;
    for(int l = 0; l < 2; l++) for(int r = 0; r < 2; r++) for(int m = 0; m < 2; m++) f[l][r][m][u] = 1e18;
    f[0][0][0][u] = f[1][1][1][u] = 0;
  }
  int first = 1;
  for(auto &[v, w] : adj[u]) {
    dfs(v);
    for(int l = 0; l < 2; l++) for(int r = 0; r < 2; r++) for(int m = 0; m < 2; m++) g[l][r][m] = 1e18;
    if (first) {
//      cout << g[1][1][1] << endl;
      for(int l = 0; l < 2; l++) for(int r = 0; r < 2; r++) for(int m1 = 0; m1 < 2; m1++) for(int m2 = 0; m2 < 2; m2++) {
        g[l][r][m1] = min(g[l][r][m1], f[l][r][m2][v] + (m1 == m2) * w);
//        if (g[1][1][1] == 0) {
//          cout << l << " " << r << " " << m1 << " " << m2 << endl;
//          exit(0);
//        }
      }
      for(int l = 0; l < 2; l++) for(int r = 0; r < 2; r++) for(int m = 0; m < 2; m++) f[l][r][m][u] = g[l][r][m];
      first = 0;
//      if (v == 1) {
//        cout << f[1][1][1][0] << endl;
//        cout << f[1][1][0][1] << endl;
//      }
      ed[u] = ed[v];
      continue;
    }

//    if (v == 2) cout << adj_leaf[ed[u]] << " " << ed[u] << endl;

    for(int l1 = 0; l1 < 2; l1++) for(int r1 = 0; r1 < 2; r1++) for(int m1 = 0; m1 < 2; m1++) {
      for(int l2 = 0; l2 < 2; l2++) for(int r2 = 0; r2 < 2; r2++) for(int m2 = 0; m2 < 2; m2++) {
        g[l1][r2][m1] = min(g[l1][r2][m1], f[l1][r1][m1][u] + f[l2][r2][m2][v] +
                               (m1 == m2) * w + (r1 == l2) * adj_leaf[ed[u]]);
//        if (v == 2 && l1 == 1 && r2 == 0 && m1 == 1 && g[l1][r2][m1] == 0) {
//          cout << f[l1][r1][m1][u] + f[l2][r2][m2][v] << endl;
//          cout << l1 << " " << r1 << " " << m1 << " " << l2 << " " << r2 << " " << m2 << endl;
//          exit(0);
//        }
      }
    }

    for(int l = 0; l < 2; l++) for(int r = 0; r < 2; r++) for(int m = 0; m < 2; m++) f[l][r][m][u] = g[l][r][m];
    if (v == 2) {
//      for(int l = 0; l < 2; l++) for(int r = 0; r < 2; r++) for(int m = 0; m < 2; m++) if (f[l][r][m][u] == 0) {
//        cout << l << " " << r << " " << m << endl;
//      }
    }
    ed[u] = ed[v];
  }
}

long long place_police (vector<int> p, vector<long long> c, vector<long long> w) {
  int n = p.size() + 1;
  for(int i = 0; i + 1 < n; i++) {
    adj[p[i]].emplace_back(i + 1, c[i]);
  }
  for(int i = 0; i < w.size(); i++) adj_leaf[i + 1] = w[i];
  dfs(0);
////  cout << f[0][0][0][0] << endl;
  long long ans = 1e18;
  for(int l = 0; l < 2; l++) for(int r = 0; r < 2; r++) for(int m = 0; m < 2; m++) {
    ans = min(ans, f[l][r][m][0] + (l == r) * w.back());
//    if (ans == 0) cout << l << " " << r << " " << m << endl;
  }
  return ans;
}

#ifdef ngu
int main() {

  freopen ("task.inp", "r", stdin);
  freopen ("task.out", "w", stdout);

//  #define [ {
//  #define ] }
  cout << place_police({0, 0, 0}, {9, 8, 0}, {9, 9, 9});
  exit(0);

  int n; cin >> n;

  int k; cin >> k;

  vector<int> p(n - 1);
  vector<long long> c(n - 1);
  vector<long long> w(k);

  for(int i = 0; i < n - 1; i++) cin >> p[i] >> c[i];

  for(int i = 0; i < k; i++) cin >> w[i];

  cout << place_police(p, c, w);
}
#endif // ngu


詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 12068kb

input:

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

output:

-1454527473

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #28:

score: 0
Wrong Answer
time: 18ms
memory: 18452kb

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:

-72733632397465

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #36:

score: 0
Wrong Answer
time: 2ms
memory: 12028kb

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:

-2909519871

result:

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

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Wrong Answer

Test #77:

score: 0
Wrong Answer
time: 8ms
memory: 14976kb

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:

-41248209360

result:

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

Subtask #6:

score: 0
Skipped

Dependency #1:

0%