Submission #1010329

# Submission time Handle Problem Language Result Execution time Memory
1010329 2024-06-28T19:36:14 Z AdamGS Worst Reporter 4 (JOI21_worst_reporter4) C++17
79 / 100
210 ms 58632 KB
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=2e5+7;
vector<int>V[LIM];
ll A[LIM], T[LIM], C[LIM], odw[LIM], cykl[LIM], root[LIM], ile[LIM];
void DFS(int x) {
  ile[x]=1;
  for(auto i : V[x]) {
    DFS(i);
    ile[x]+=ile[i];
  }
  rep(i, V[x].size()) if(ile[V[x][i]]>ile[V[x][0]]) swap(V[x][i], V[x][0]);
}
void DFS2(int x, multiset<pair<ll,ll>>&S) {
  if(V[x].size()) DFS2(V[x][0], S);
  for(int i=1; i<V[x].size(); ++i) {
    multiset<pair<ll,ll>>P;
    DFS2(V[x][i], P);
    for(auto j : P) S.insert(j);
  }
  ll a=C[x];
  while(a) {
    auto it=S.lower_bound({T[x], -1});
    if(it==S.begin()) break;
    --it;
    auto p=*it;
    S.erase(S.find(p));
    if(p.nd<=a) {
      a-=p.nd;
      continue;
    }
    p.nd-=a;
    a=0;
    S.insert(p);
  }
  S.insert({T[x], C[x]});
}
int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  rep(i, n) {
    cin >> A[i] >> T[i] >> C[i];
    --A[i];
  }
  rep(i, n) if(!odw[i]) {
    int p=i;
    while(!odw[p]) {
      odw[p]=i+1;
      p=A[p];
    }
    if(odw[p]!=i+1) continue;
    int x=A[p];
    vector<ll>P;
    while(x!=p) {
      P.pb(T[x]);
      cykl[x]=1;
      root[x]=p;
      x=A[x];
    }
    P.pb(T[x]);
    cykl[x]=1;
    root[x]=p;
    sort(all(P));
    x=p;
    for(auto j : P) {
      T[x]=j;
      if(A[x]==p) A[x]=x;
      x=A[x];
    }
  }
  rep(i, n) if(!cykl[i] && cykl[A[i]]) A[i]=root[A[i]];
  rep(i, n) if(A[i]!=i) V[A[i]].pb(i);
  ll sum=0;
  rep(i, n) sum+=C[i];
  rep(i, n) if(A[i]==i) {
    DFS(i);
    multiset<pair<ll,ll>>S;
    DFS2(i, S);
    for(auto j : S) sum-=j.nd;
  }
  cout << sum << '\n';
}

Compilation message

worst_reporter2.cpp: In function 'void DFS(int)':
worst_reporter2.cpp:5:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
worst_reporter2.cpp:19:3: note: in expansion of macro 'rep'
   19 |   rep(i, V[x].size()) if(ile[V[x][i]]>ile[V[x][0]]) swap(V[x][i], V[x][0]);
      |   ^~~
worst_reporter2.cpp: In function 'void DFS2(int, std::multiset<std::pair<long long int, long long int> >&)':
worst_reporter2.cpp:23:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |   for(int i=1; i<V[x].size(); ++i) {
      |                ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 15704 KB Output is correct
2 Correct 2 ms 15708 KB Output is correct
3 Correct 2 ms 15708 KB Output is correct
4 Correct 2 ms 15708 KB Output is correct
5 Correct 4 ms 16216 KB Output is correct
6 Correct 4 ms 16220 KB Output is correct
7 Correct 4 ms 16196 KB Output is correct
8 Correct 5 ms 16220 KB Output is correct
9 Correct 4 ms 16220 KB Output is correct
10 Correct 4 ms 16220 KB Output is correct
11 Correct 5 ms 16216 KB Output is correct
12 Correct 5 ms 16732 KB Output is correct
13 Correct 5 ms 16988 KB Output is correct
14 Correct 4 ms 16476 KB Output is correct
15 Correct 5 ms 16476 KB Output is correct
16 Correct 5 ms 16220 KB Output is correct
17 Correct 6 ms 16216 KB Output is correct
18 Correct 6 ms 16476 KB Output is correct
19 Correct 4 ms 16476 KB Output is correct
20 Correct 5 ms 16728 KB Output is correct
21 Correct 4 ms 16732 KB Output is correct
22 Correct 3 ms 16324 KB Output is correct
23 Correct 4 ms 16220 KB Output is correct
24 Correct 5 ms 16552 KB Output is correct
25 Correct 5 ms 16732 KB Output is correct
26 Correct 4 ms 16728 KB Output is correct
27 Correct 4 ms 16472 KB Output is correct
28 Correct 4 ms 16728 KB Output is correct
29 Correct 5 ms 16748 KB Output is correct
30 Correct 5 ms 16988 KB Output is correct
31 Correct 7 ms 16988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 15704 KB Output is correct
2 Correct 2 ms 15708 KB Output is correct
3 Correct 2 ms 15708 KB Output is correct
4 Correct 2 ms 15708 KB Output is correct
5 Correct 4 ms 16216 KB Output is correct
6 Correct 4 ms 16220 KB Output is correct
7 Correct 4 ms 16196 KB Output is correct
8 Correct 5 ms 16220 KB Output is correct
9 Correct 4 ms 16220 KB Output is correct
10 Correct 4 ms 16220 KB Output is correct
11 Correct 5 ms 16216 KB Output is correct
12 Correct 5 ms 16732 KB Output is correct
13 Correct 5 ms 16988 KB Output is correct
14 Correct 4 ms 16476 KB Output is correct
15 Correct 5 ms 16476 KB Output is correct
16 Correct 5 ms 16220 KB Output is correct
17 Correct 6 ms 16216 KB Output is correct
18 Correct 6 ms 16476 KB Output is correct
19 Correct 4 ms 16476 KB Output is correct
20 Correct 5 ms 16728 KB Output is correct
21 Correct 4 ms 16732 KB Output is correct
22 Correct 3 ms 16324 KB Output is correct
23 Correct 4 ms 16220 KB Output is correct
24 Correct 5 ms 16552 KB Output is correct
25 Correct 5 ms 16732 KB Output is correct
26 Correct 4 ms 16728 KB Output is correct
27 Correct 4 ms 16472 KB Output is correct
28 Correct 4 ms 16728 KB Output is correct
29 Correct 5 ms 16748 KB Output is correct
30 Correct 5 ms 16988 KB Output is correct
31 Correct 7 ms 16988 KB Output is correct
32 Correct 5 ms 16216 KB Output is correct
33 Correct 170 ms 31572 KB Output is correct
34 Correct 178 ms 30512 KB Output is correct
35 Correct 147 ms 29524 KB Output is correct
36 Correct 150 ms 30692 KB Output is correct
37 Correct 169 ms 33108 KB Output is correct
38 Correct 171 ms 31828 KB Output is correct
39 Correct 139 ms 53556 KB Output is correct
40 Correct 138 ms 53604 KB Output is correct
41 Correct 123 ms 56912 KB Output is correct
42 Correct 122 ms 37940 KB Output is correct
43 Correct 136 ms 38224 KB Output is correct
44 Correct 156 ms 31316 KB Output is correct
45 Correct 161 ms 31568 KB Output is correct
46 Correct 210 ms 35920 KB Output is correct
47 Correct 160 ms 41812 KB Output is correct
48 Correct 166 ms 45392 KB Output is correct
49 Correct 124 ms 46068 KB Output is correct
50 Correct 96 ms 29356 KB Output is correct
51 Correct 110 ms 29300 KB Output is correct
52 Correct 146 ms 42440 KB Output is correct
53 Correct 152 ms 46120 KB Output is correct
54 Correct 69 ms 53584 KB Output is correct
55 Correct 106 ms 44180 KB Output is correct
56 Correct 102 ms 54100 KB Output is correct
57 Correct 112 ms 58632 KB Output is correct
58 Correct 130 ms 56600 KB Output is correct
59 Correct 118 ms 56660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 15704 KB Output is correct
2 Correct 2 ms 15708 KB Output is correct
3 Correct 2 ms 15708 KB Output is correct
4 Correct 2 ms 15708 KB Output is correct
5 Correct 4 ms 16216 KB Output is correct
6 Correct 4 ms 16220 KB Output is correct
7 Correct 4 ms 16196 KB Output is correct
8 Correct 5 ms 16220 KB Output is correct
9 Correct 4 ms 16220 KB Output is correct
10 Correct 4 ms 16220 KB Output is correct
11 Correct 5 ms 16216 KB Output is correct
12 Correct 5 ms 16732 KB Output is correct
13 Correct 5 ms 16988 KB Output is correct
14 Correct 4 ms 16476 KB Output is correct
15 Correct 5 ms 16476 KB Output is correct
16 Correct 5 ms 16220 KB Output is correct
17 Correct 6 ms 16216 KB Output is correct
18 Correct 6 ms 16476 KB Output is correct
19 Correct 4 ms 16476 KB Output is correct
20 Correct 5 ms 16728 KB Output is correct
21 Correct 4 ms 16732 KB Output is correct
22 Correct 3 ms 16324 KB Output is correct
23 Correct 4 ms 16220 KB Output is correct
24 Correct 5 ms 16552 KB Output is correct
25 Correct 5 ms 16732 KB Output is correct
26 Correct 4 ms 16728 KB Output is correct
27 Correct 4 ms 16472 KB Output is correct
28 Correct 4 ms 16728 KB Output is correct
29 Correct 5 ms 16748 KB Output is correct
30 Correct 5 ms 16988 KB Output is correct
31 Correct 7 ms 16988 KB Output is correct
32 Correct 5 ms 16216 KB Output is correct
33 Correct 170 ms 31572 KB Output is correct
34 Correct 178 ms 30512 KB Output is correct
35 Correct 147 ms 29524 KB Output is correct
36 Correct 150 ms 30692 KB Output is correct
37 Correct 169 ms 33108 KB Output is correct
38 Correct 171 ms 31828 KB Output is correct
39 Correct 139 ms 53556 KB Output is correct
40 Correct 138 ms 53604 KB Output is correct
41 Correct 123 ms 56912 KB Output is correct
42 Correct 122 ms 37940 KB Output is correct
43 Correct 136 ms 38224 KB Output is correct
44 Correct 156 ms 31316 KB Output is correct
45 Correct 161 ms 31568 KB Output is correct
46 Correct 210 ms 35920 KB Output is correct
47 Correct 160 ms 41812 KB Output is correct
48 Correct 166 ms 45392 KB Output is correct
49 Correct 124 ms 46068 KB Output is correct
50 Correct 96 ms 29356 KB Output is correct
51 Correct 110 ms 29300 KB Output is correct
52 Correct 146 ms 42440 KB Output is correct
53 Correct 152 ms 46120 KB Output is correct
54 Correct 69 ms 53584 KB Output is correct
55 Correct 106 ms 44180 KB Output is correct
56 Correct 102 ms 54100 KB Output is correct
57 Correct 112 ms 58632 KB Output is correct
58 Correct 130 ms 56600 KB Output is correct
59 Correct 118 ms 56660 KB Output is correct
60 Correct 2 ms 15704 KB Output is correct
61 Correct 3 ms 15708 KB Output is correct
62 Correct 2 ms 15708 KB Output is correct
63 Correct 2 ms 15708 KB Output is correct
64 Correct 181 ms 31376 KB Output is correct
65 Incorrect 157 ms 29780 KB Output isn't correct
66 Halted 0 ms 0 KB -