Submission #916612

# Submission time Handle Problem Language Result Execution time Memory
916612 2024-01-26T07:14:40 Z Tuanlinh123 Worst Reporter 4 (JOI21_worst_reporter4) C++11
100 / 100
351 ms 109744 KB
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define fi first
#define se second
using namespace std;
 
const ll maxn=200005;
ll A[maxn], H[maxn], C[maxn], deg[maxn];
map<ll, ll> cnt[maxn];
 
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n, sum=0; cin >> n;
    for (ll i=1; i<=n; i++)
        cin>>A[i]>>H[i]>>C[i], sum+=C[i], deg[A[i]]++;
    queue <ll> q;
    for (ll i=1; i<=n; i++) 
        if (!deg[i]) q.push(i);
    auto Merge=[&](map<ll, ll> &a, map<ll, ll> &b)
    {
        if (a.size()<b.size()) swap(a, b);
        for (pll i:b) a[i.fi]+=i.se;
    };
    auto Fix=[&](map<ll, ll> &a, ll H, ll C)
    {
        a[H]+=C; auto it=a.lower_bound(H);
        while (it!=a.begin())
        {
            it--;
            if ((*it).se>C) {(*it).se-=C; break;}
            C-=(*it).se; it=a.erase(it);
        }
    };
    while (!q.empty())
    {
        ll u=q.front(), crr=C[u]; q.pop();
        deg[A[u]]--; 
        Fix(cnt[u], H[u], C[u]);
        Merge(cnt[A[u]], cnt[u]);
        if (!deg[A[u]]) q.push(A[u]);
    }
    for (ll i=1; i<=n; i++)
    {
        if (!deg[i]) continue; deg[i]=0;
        map <ll, ll> all=cnt[i], cn; cn[H[i]]+=C[i];
        for (ll crr=A[i]; crr!=i; crr=A[crr])
            Merge(all, cnt[crr]), deg[crr]=0, cn[H[crr]]+=C[crr];
        for (pll j:cn) Fix(all, j.fi, j.se);
        for (pll j:all) sum-=j.se;
    }
    cout << sum << "\n";
}

Compilation message

worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:38:25: warning: unused variable 'crr' [-Wunused-variable]
   38 |         ll u=q.front(), crr=C[u]; q.pop();
      |                         ^~~
worst_reporter2.cpp:46:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   46 |         if (!deg[i]) continue; deg[i]=0;
      |         ^~
worst_reporter2.cpp:46:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   46 |         if (!deg[i]) continue; deg[i]=0;
      |                                ^~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14940 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 3 ms 14940 KB Output is correct
4 Correct 4 ms 14940 KB Output is correct
5 Correct 8 ms 16476 KB Output is correct
6 Correct 7 ms 15708 KB Output is correct
7 Correct 3 ms 15604 KB Output is correct
8 Correct 8 ms 16472 KB Output is correct
9 Correct 6 ms 15708 KB Output is correct
10 Correct 6 ms 15452 KB Output is correct
11 Correct 5 ms 15196 KB Output is correct
12 Correct 5 ms 14940 KB Output is correct
13 Correct 5 ms 14960 KB Output is correct
14 Correct 6 ms 14940 KB Output is correct
15 Correct 5 ms 14940 KB Output is correct
16 Correct 8 ms 16712 KB Output is correct
17 Correct 6 ms 15708 KB Output is correct
18 Correct 5 ms 15196 KB Output is correct
19 Correct 6 ms 15436 KB Output is correct
20 Correct 5 ms 15196 KB Output is correct
21 Correct 5 ms 15196 KB Output is correct
22 Correct 6 ms 15964 KB Output is correct
23 Correct 5 ms 15196 KB Output is correct
24 Correct 6 ms 15452 KB Output is correct
25 Correct 5 ms 15192 KB Output is correct
26 Correct 6 ms 15004 KB Output is correct
27 Correct 6 ms 15708 KB Output is correct
28 Correct 6 ms 15708 KB Output is correct
29 Correct 6 ms 15516 KB Output is correct
30 Correct 9 ms 15708 KB Output is correct
31 Correct 6 ms 15704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14940 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 3 ms 14940 KB Output is correct
4 Correct 4 ms 14940 KB Output is correct
5 Correct 8 ms 16476 KB Output is correct
6 Correct 7 ms 15708 KB Output is correct
7 Correct 3 ms 15604 KB Output is correct
8 Correct 8 ms 16472 KB Output is correct
9 Correct 6 ms 15708 KB Output is correct
10 Correct 6 ms 15452 KB Output is correct
11 Correct 5 ms 15196 KB Output is correct
12 Correct 5 ms 14940 KB Output is correct
13 Correct 5 ms 14960 KB Output is correct
14 Correct 6 ms 14940 KB Output is correct
15 Correct 5 ms 14940 KB Output is correct
16 Correct 8 ms 16712 KB Output is correct
17 Correct 6 ms 15708 KB Output is correct
18 Correct 5 ms 15196 KB Output is correct
19 Correct 6 ms 15436 KB Output is correct
20 Correct 5 ms 15196 KB Output is correct
21 Correct 5 ms 15196 KB Output is correct
22 Correct 6 ms 15964 KB Output is correct
23 Correct 5 ms 15196 KB Output is correct
24 Correct 6 ms 15452 KB Output is correct
25 Correct 5 ms 15192 KB Output is correct
26 Correct 6 ms 15004 KB Output is correct
27 Correct 6 ms 15708 KB Output is correct
28 Correct 6 ms 15708 KB Output is correct
29 Correct 6 ms 15516 KB Output is correct
30 Correct 9 ms 15708 KB Output is correct
31 Correct 6 ms 15704 KB Output is correct
32 Correct 8 ms 16476 KB Output is correct
33 Correct 338 ms 99664 KB Output is correct
34 Correct 252 ms 59556 KB Output is correct
35 Correct 351 ms 99080 KB Output is correct
36 Correct 274 ms 59292 KB Output is correct
37 Correct 122 ms 33268 KB Output is correct
38 Correct 82 ms 27476 KB Output is correct
39 Correct 85 ms 21216 KB Output is correct
40 Correct 81 ms 21264 KB Output is correct
41 Correct 56 ms 21232 KB Output is correct
42 Correct 83 ms 21300 KB Output is correct
43 Correct 77 ms 21260 KB Output is correct
44 Correct 295 ms 109744 KB Output is correct
45 Correct 202 ms 65108 KB Output is correct
46 Correct 55 ms 27732 KB Output is correct
47 Correct 148 ms 41400 KB Output is correct
48 Correct 77 ms 27712 KB Output is correct
49 Correct 56 ms 27336 KB Output is correct
50 Correct 239 ms 57940 KB Output is correct
51 Correct 67 ms 33096 KB Output is correct
52 Correct 192 ms 41964 KB Output is correct
53 Correct 76 ms 27540 KB Output is correct
54 Correct 57 ms 21332 KB Output is correct
55 Correct 135 ms 47424 KB Output is correct
56 Correct 121 ms 43376 KB Output is correct
57 Correct 101 ms 43388 KB Output is correct
58 Correct 220 ms 51832 KB Output is correct
59 Correct 192 ms 51808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14940 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 3 ms 14940 KB Output is correct
4 Correct 4 ms 14940 KB Output is correct
5 Correct 8 ms 16476 KB Output is correct
6 Correct 7 ms 15708 KB Output is correct
7 Correct 3 ms 15604 KB Output is correct
8 Correct 8 ms 16472 KB Output is correct
9 Correct 6 ms 15708 KB Output is correct
10 Correct 6 ms 15452 KB Output is correct
11 Correct 5 ms 15196 KB Output is correct
12 Correct 5 ms 14940 KB Output is correct
13 Correct 5 ms 14960 KB Output is correct
14 Correct 6 ms 14940 KB Output is correct
15 Correct 5 ms 14940 KB Output is correct
16 Correct 8 ms 16712 KB Output is correct
17 Correct 6 ms 15708 KB Output is correct
18 Correct 5 ms 15196 KB Output is correct
19 Correct 6 ms 15436 KB Output is correct
20 Correct 5 ms 15196 KB Output is correct
21 Correct 5 ms 15196 KB Output is correct
22 Correct 6 ms 15964 KB Output is correct
23 Correct 5 ms 15196 KB Output is correct
24 Correct 6 ms 15452 KB Output is correct
25 Correct 5 ms 15192 KB Output is correct
26 Correct 6 ms 15004 KB Output is correct
27 Correct 6 ms 15708 KB Output is correct
28 Correct 6 ms 15708 KB Output is correct
29 Correct 6 ms 15516 KB Output is correct
30 Correct 9 ms 15708 KB Output is correct
31 Correct 6 ms 15704 KB Output is correct
32 Correct 8 ms 16476 KB Output is correct
33 Correct 338 ms 99664 KB Output is correct
34 Correct 252 ms 59556 KB Output is correct
35 Correct 351 ms 99080 KB Output is correct
36 Correct 274 ms 59292 KB Output is correct
37 Correct 122 ms 33268 KB Output is correct
38 Correct 82 ms 27476 KB Output is correct
39 Correct 85 ms 21216 KB Output is correct
40 Correct 81 ms 21264 KB Output is correct
41 Correct 56 ms 21232 KB Output is correct
42 Correct 83 ms 21300 KB Output is correct
43 Correct 77 ms 21260 KB Output is correct
44 Correct 295 ms 109744 KB Output is correct
45 Correct 202 ms 65108 KB Output is correct
46 Correct 55 ms 27732 KB Output is correct
47 Correct 148 ms 41400 KB Output is correct
48 Correct 77 ms 27712 KB Output is correct
49 Correct 56 ms 27336 KB Output is correct
50 Correct 239 ms 57940 KB Output is correct
51 Correct 67 ms 33096 KB Output is correct
52 Correct 192 ms 41964 KB Output is correct
53 Correct 76 ms 27540 KB Output is correct
54 Correct 57 ms 21332 KB Output is correct
55 Correct 135 ms 47424 KB Output is correct
56 Correct 121 ms 43376 KB Output is correct
57 Correct 101 ms 43388 KB Output is correct
58 Correct 220 ms 51832 KB Output is correct
59 Correct 192 ms 51808 KB Output is correct
60 Correct 5 ms 14940 KB Output is correct
61 Correct 3 ms 14940 KB Output is correct
62 Correct 4 ms 14952 KB Output is correct
63 Correct 4 ms 14940 KB Output is correct
64 Correct 254 ms 61012 KB Output is correct
65 Correct 198 ms 44160 KB Output is correct
66 Correct 290 ms 59516 KB Output is correct
67 Correct 230 ms 44420 KB Output is correct
68 Correct 116 ms 29504 KB Output is correct
69 Correct 82 ms 26060 KB Output is correct
70 Correct 149 ms 29776 KB Output is correct
71 Correct 81 ms 21404 KB Output is correct
72 Correct 208 ms 33712 KB Output is correct
73 Correct 72 ms 21076 KB Output is correct
74 Correct 292 ms 41748 KB Output is correct
75 Correct 118 ms 27476 KB Output is correct
76 Correct 90 ms 27340 KB Output is correct
77 Correct 220 ms 41532 KB Output is correct
78 Correct 75 ms 27476 KB Output is correct
79 Correct 255 ms 60424 KB Output is correct
80 Correct 161 ms 40400 KB Output is correct
81 Correct 112 ms 27168 KB Output is correct
82 Correct 124 ms 33756 KB Output is correct
83 Correct 58 ms 21232 KB Output is correct
84 Correct 166 ms 36396 KB Output is correct
85 Correct 176 ms 36636 KB Output is correct
86 Correct 145 ms 33108 KB Output is correct
87 Correct 173 ms 36180 KB Output is correct
88 Correct 179 ms 36308 KB Output is correct