답안 #932499

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
932499 2024-02-23T14:04:59 Z andrei_boaca Worst Reporter 4 (JOI21_worst_reporter4) C++17
79 / 100
409 ms 75196 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll INF=1e17;
map<ll,ll> nrm;
ll nr;
vector<ll> muchii[200005];
ll n,par[200005],v[200005],cost[200005];
set<pll> setik[200005];
void add(ll nod,ll poz,ll val)
{
    auto it=setik[nod].lower_bound({poz,0});
    if((*it).first==poz)
    {
        ll x=(*it).second+val;
        setik[nod].erase(it);
        setik[nod].insert({poz,x});
    }
    else
        setik[nod].insert({poz,val});
}
void dfs(ll nod)
{
    if(muchii[nod].empty())
    {
        add(nod,v[nod]+1,cost[nod]);
        return;
    }
    ll maxim=0;
    ll who=0;
    for(int i:muchii[nod])
    {
        dfs(i);
        if(setik[i].size()>maxim)
        {
            maxim=setik[i].size();
            who=i;
        }
    }
    swap(setik[nod],setik[who]);
    for(int i:muchii[nod])
        if(i!=who)
        {
            for(auto j:setik[i])
                add(nod,j.first,j.second);
            setik[i].clear();
        }
    add(nod,1,cost[nod]);
    ll dif=cost[nod];
    while(!setik[nod].empty()&&dif>0)
    {
        auto it=prev(setik[nod].upper_bound({v[nod],INF}));
        ll poz=(*it).first;
        ll x=(*it).second;
        ll val=min(dif,x);
        x-=val;
        dif-=val;
        setik[nod].erase(it);
        if(x!=0)
            setik[nod].insert({poz,x});
    }
    add(nod,v[nod]+1,cost[nod]);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    vector<ll> vals;
    for(int i=1;i<=n;i++)
    {
        cin>>par[i]>>v[i]>>cost[i];
        if(i!=1)
            muchii[par[i]].push_back(i);
        vals.push_back(v[i]);
    }
    sort(vals.begin(),vals.end());
    vals.erase(unique(vals.begin(),vals.end()),vals.end());
    for(int i=0;i<vals.size();i++)
        nrm[vals[i]]=i+1;
    nr=vals.size();
    for(int i=1;i<=n;i++)
        v[i]=nrm[v[i]];
    dfs(1);
    auto it=setik[1].begin();
    if((*it).first==1)
        cout<<(*it).second;
    else
        cout<<0;
    return 0;
}

Compilation message

worst_reporter2.cpp: In function 'void dfs(ll)':
worst_reporter2.cpp:36:27: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   36 |         if(setik[i].size()>maxim)
      |            ~~~~~~~~~~~~~~~^~~~~~
worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:81:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     for(int i=0;i<vals.size();i++)
      |                 ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19036 KB Output is correct
2 Correct 5 ms 19036 KB Output is correct
3 Correct 5 ms 19240 KB Output is correct
4 Correct 4 ms 19036 KB Output is correct
5 Correct 9 ms 19800 KB Output is correct
6 Correct 7 ms 19288 KB Output is correct
7 Correct 6 ms 19288 KB Output is correct
8 Correct 10 ms 19804 KB Output is correct
9 Correct 7 ms 19276 KB Output is correct
10 Correct 7 ms 19292 KB Output is correct
11 Correct 5 ms 19292 KB Output is correct
12 Correct 10 ms 20400 KB Output is correct
13 Correct 8 ms 20060 KB Output is correct
14 Correct 10 ms 19984 KB Output is correct
15 Correct 7 ms 19548 KB Output is correct
16 Correct 10 ms 19956 KB Output is correct
17 Correct 8 ms 19292 KB Output is correct
18 Correct 5 ms 19292 KB Output is correct
19 Correct 9 ms 20060 KB Output is correct
20 Correct 7 ms 19548 KB Output is correct
21 Correct 7 ms 19548 KB Output is correct
22 Correct 7 ms 19804 KB Output is correct
23 Correct 6 ms 19548 KB Output is correct
24 Correct 9 ms 19964 KB Output is correct
25 Correct 7 ms 19804 KB Output is correct
26 Correct 7 ms 20316 KB Output is correct
27 Correct 7 ms 20060 KB Output is correct
28 Correct 10 ms 20236 KB Output is correct
29 Correct 8 ms 20324 KB Output is correct
30 Correct 9 ms 20316 KB Output is correct
31 Correct 9 ms 20536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19036 KB Output is correct
2 Correct 5 ms 19036 KB Output is correct
3 Correct 5 ms 19240 KB Output is correct
4 Correct 4 ms 19036 KB Output is correct
5 Correct 9 ms 19800 KB Output is correct
6 Correct 7 ms 19288 KB Output is correct
7 Correct 6 ms 19288 KB Output is correct
8 Correct 10 ms 19804 KB Output is correct
9 Correct 7 ms 19276 KB Output is correct
10 Correct 7 ms 19292 KB Output is correct
11 Correct 5 ms 19292 KB Output is correct
12 Correct 10 ms 20400 KB Output is correct
13 Correct 8 ms 20060 KB Output is correct
14 Correct 10 ms 19984 KB Output is correct
15 Correct 7 ms 19548 KB Output is correct
16 Correct 10 ms 19956 KB Output is correct
17 Correct 8 ms 19292 KB Output is correct
18 Correct 5 ms 19292 KB Output is correct
19 Correct 9 ms 20060 KB Output is correct
20 Correct 7 ms 19548 KB Output is correct
21 Correct 7 ms 19548 KB Output is correct
22 Correct 7 ms 19804 KB Output is correct
23 Correct 6 ms 19548 KB Output is correct
24 Correct 9 ms 19964 KB Output is correct
25 Correct 7 ms 19804 KB Output is correct
26 Correct 7 ms 20316 KB Output is correct
27 Correct 7 ms 20060 KB Output is correct
28 Correct 10 ms 20236 KB Output is correct
29 Correct 8 ms 20324 KB Output is correct
30 Correct 9 ms 20316 KB Output is correct
31 Correct 9 ms 20536 KB Output is correct
32 Correct 10 ms 19804 KB Output is correct
33 Correct 409 ms 49608 KB Output is correct
34 Correct 207 ms 30000 KB Output is correct
35 Correct 402 ms 53148 KB Output is correct
36 Correct 219 ms 30076 KB Output is correct
37 Correct 130 ms 29372 KB Output is correct
38 Correct 113 ms 29376 KB Output is correct
39 Correct 273 ms 69820 KB Output is correct
40 Correct 177 ms 57292 KB Output is correct
41 Correct 109 ms 57024 KB Output is correct
42 Correct 258 ms 57292 KB Output is correct
43 Correct 166 ms 44680 KB Output is correct
44 Correct 378 ms 53696 KB Output is correct
45 Correct 209 ms 29616 KB Output is correct
46 Correct 74 ms 28852 KB Output is correct
47 Correct 306 ms 60860 KB Output is correct
48 Correct 169 ms 41420 KB Output is correct
49 Correct 97 ms 41368 KB Output is correct
50 Correct 244 ms 51624 KB Output is correct
51 Correct 111 ms 39104 KB Output is correct
52 Correct 333 ms 61992 KB Output is correct
53 Correct 145 ms 48640 KB Output is correct
54 Correct 151 ms 69820 KB Output is correct
55 Correct 205 ms 63168 KB Output is correct
56 Correct 213 ms 70864 KB Output is correct
57 Correct 202 ms 74628 KB Output is correct
58 Correct 283 ms 75164 KB Output is correct
59 Correct 255 ms 75196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19036 KB Output is correct
2 Correct 5 ms 19036 KB Output is correct
3 Correct 5 ms 19240 KB Output is correct
4 Correct 4 ms 19036 KB Output is correct
5 Correct 9 ms 19800 KB Output is correct
6 Correct 7 ms 19288 KB Output is correct
7 Correct 6 ms 19288 KB Output is correct
8 Correct 10 ms 19804 KB Output is correct
9 Correct 7 ms 19276 KB Output is correct
10 Correct 7 ms 19292 KB Output is correct
11 Correct 5 ms 19292 KB Output is correct
12 Correct 10 ms 20400 KB Output is correct
13 Correct 8 ms 20060 KB Output is correct
14 Correct 10 ms 19984 KB Output is correct
15 Correct 7 ms 19548 KB Output is correct
16 Correct 10 ms 19956 KB Output is correct
17 Correct 8 ms 19292 KB Output is correct
18 Correct 5 ms 19292 KB Output is correct
19 Correct 9 ms 20060 KB Output is correct
20 Correct 7 ms 19548 KB Output is correct
21 Correct 7 ms 19548 KB Output is correct
22 Correct 7 ms 19804 KB Output is correct
23 Correct 6 ms 19548 KB Output is correct
24 Correct 9 ms 19964 KB Output is correct
25 Correct 7 ms 19804 KB Output is correct
26 Correct 7 ms 20316 KB Output is correct
27 Correct 7 ms 20060 KB Output is correct
28 Correct 10 ms 20236 KB Output is correct
29 Correct 8 ms 20324 KB Output is correct
30 Correct 9 ms 20316 KB Output is correct
31 Correct 9 ms 20536 KB Output is correct
32 Correct 10 ms 19804 KB Output is correct
33 Correct 409 ms 49608 KB Output is correct
34 Correct 207 ms 30000 KB Output is correct
35 Correct 402 ms 53148 KB Output is correct
36 Correct 219 ms 30076 KB Output is correct
37 Correct 130 ms 29372 KB Output is correct
38 Correct 113 ms 29376 KB Output is correct
39 Correct 273 ms 69820 KB Output is correct
40 Correct 177 ms 57292 KB Output is correct
41 Correct 109 ms 57024 KB Output is correct
42 Correct 258 ms 57292 KB Output is correct
43 Correct 166 ms 44680 KB Output is correct
44 Correct 378 ms 53696 KB Output is correct
45 Correct 209 ms 29616 KB Output is correct
46 Correct 74 ms 28852 KB Output is correct
47 Correct 306 ms 60860 KB Output is correct
48 Correct 169 ms 41420 KB Output is correct
49 Correct 97 ms 41368 KB Output is correct
50 Correct 244 ms 51624 KB Output is correct
51 Correct 111 ms 39104 KB Output is correct
52 Correct 333 ms 61992 KB Output is correct
53 Correct 145 ms 48640 KB Output is correct
54 Correct 151 ms 69820 KB Output is correct
55 Correct 205 ms 63168 KB Output is correct
56 Correct 213 ms 70864 KB Output is correct
57 Correct 202 ms 74628 KB Output is correct
58 Correct 283 ms 75164 KB Output is correct
59 Correct 255 ms 75196 KB Output is correct
60 Correct 5 ms 19292 KB Output is correct
61 Incorrect 4 ms 19032 KB Output isn't correct
62 Halted 0 ms 0 KB -