답안 #894074

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
894074 2023-12-28T00:12:59 Z danikoynov Worst Reporter 4 (JOI21_worst_reporter4) C++14
79 / 100
425 ms 524288 KB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


const int maxn = 2e5 + 10;
const ll inf = 1e18;

int n, a[maxn], h[maxn];
ll c[maxn];
vector < int > adj[maxn];
void input()
{
    cin >> n;
    for (int i = 1; i <= n; i ++)
    {
        cin >> a[i] >> h[i] >> c[i];
        if (a[i] != i)
            adj[a[i]].push_back(i);
    }
}

unordered_map < int, int > tag;

void compress()
{
    vector < int > values;
    for (int i = 1; i <= n; i ++)
        values.push_back(h[i]);

    sort(values.begin(), values.end());

    for (int i = 0; i < n; i ++)
        tag[values[i]] = i + 1;

}

ll temp[maxn];
int used[maxn];
set < pair < int, ll > > spot[maxn];

void add_to_set(int v, pair < int, ll > cur)
{
    set < pair < int, ll > > :: iterator it = spot[v].lower_bound({cur.first, -inf});

    if (it != spot[v].end() && it -> first == cur.first)
    {
        cur.second += it -> second;

        spot[v].erase(it);
    }
    spot[v].insert(cur);
}

void dfs(int v)
{


    used[v] = 1;
    for (int u : adj[v])
    {
        dfs(u);

        if (spot[u].size() > spot[v].size())
            swap(spot[v], spot[u]);

        for (pair < int, ll > cur : spot[u])
            add_to_set(v, cur);

    }


    set < pair < int, ll > > :: iterator it;
    ll sum = 0;
    while(spot[v].size() > 0)
    {

        it = spot[v].lower_bound({tag[h[v]], inf});
        ///if (it != spot[v].end())

        if (it == spot[v].begin())
            break;
        it = prev(it);

        if (sum + it -> second > c[v])
        {
            pair < int, ll > nw = *it;
            nw.second -= (c[v] - sum);
            sum = c[v];
            spot[v].erase(it);
            add_to_set(v, nw);
            ///spot[v].insert(nw);
            break;
        }
        else
        {
            sum += it -> second;
            spot[v].erase(it);
        }

    }

    /**cout << "state " << v << " " << h[v] << endl;
    for (int j = 1; j <= n; j ++)
        cout << dp[v][j] << " ";
    cout << endl;
    for (pair < int, ll > cur : spot[v])
        cout << cur.first << " " << cur.second << endl;
    cout << "----------" << endl;*/
    add_to_set(v, {1, sum});
    add_to_set(v, {tag[h[v]] + 1, c[v]});
    ///add_to_set(v, {tag[h[v]] + 1, c[v] - sum});
    //spot[v].insert({1, sum});
    ///spot[v].insert({tag[h[v]] + 1, c[v] - sum});



}
void calculate_states()
{
    ll ans = 0;
    for (int i = 1; i <= n; i ++)
    {
        if (used[i])
            continue;

        dfs(i);

        ll s = 0;
        for (pair < int, ll > cur : spot[i])
        {
            if (cur.first == 1)
                s += cur.second;
        }
        ans += s;
    }

    cout << ans << endl;
}
void solve()
{
    input();
    compress();
    calculate_states();
}

int main()
{
    speed();
    ///freopen("test.txt", "r", stdin);
    solve();
    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 19032 KB Output is correct
2 Correct 3 ms 19032 KB Output is correct
3 Correct 4 ms 19288 KB Output is correct
4 Correct 3 ms 19036 KB Output is correct
5 Correct 10 ms 20508 KB Output is correct
6 Correct 8 ms 19804 KB Output is correct
7 Correct 7 ms 19544 KB Output is correct
8 Correct 9 ms 20572 KB Output is correct
9 Correct 9 ms 19800 KB Output is correct
10 Correct 8 ms 19548 KB Output is correct
11 Correct 6 ms 19288 KB Output is correct
12 Correct 8 ms 19804 KB Output is correct
13 Correct 6 ms 19800 KB Output is correct
14 Correct 8 ms 19548 KB Output is correct
15 Correct 7 ms 19544 KB Output is correct
16 Correct 10 ms 20828 KB Output is correct
17 Correct 8 ms 20100 KB Output is correct
18 Correct 5 ms 19292 KB Output is correct
19 Correct 8 ms 20072 KB Output is correct
20 Correct 7 ms 19548 KB Output is correct
21 Correct 6 ms 19656 KB Output is correct
22 Correct 7 ms 20060 KB Output is correct
23 Correct 6 ms 19648 KB Output is correct
24 Correct 8 ms 20060 KB Output is correct
25 Correct 7 ms 19548 KB Output is correct
26 Correct 7 ms 19972 KB Output is correct
27 Correct 8 ms 20060 KB Output is correct
28 Correct 7 ms 20060 KB Output is correct
29 Correct 7 ms 20060 KB Output is correct
30 Correct 8 ms 20128 KB Output is correct
31 Correct 8 ms 20056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 19032 KB Output is correct
2 Correct 3 ms 19032 KB Output is correct
3 Correct 4 ms 19288 KB Output is correct
4 Correct 3 ms 19036 KB Output is correct
5 Correct 10 ms 20508 KB Output is correct
6 Correct 8 ms 19804 KB Output is correct
7 Correct 7 ms 19544 KB Output is correct
8 Correct 9 ms 20572 KB Output is correct
9 Correct 9 ms 19800 KB Output is correct
10 Correct 8 ms 19548 KB Output is correct
11 Correct 6 ms 19288 KB Output is correct
12 Correct 8 ms 19804 KB Output is correct
13 Correct 6 ms 19800 KB Output is correct
14 Correct 8 ms 19548 KB Output is correct
15 Correct 7 ms 19544 KB Output is correct
16 Correct 10 ms 20828 KB Output is correct
17 Correct 8 ms 20100 KB Output is correct
18 Correct 5 ms 19292 KB Output is correct
19 Correct 8 ms 20072 KB Output is correct
20 Correct 7 ms 19548 KB Output is correct
21 Correct 6 ms 19656 KB Output is correct
22 Correct 7 ms 20060 KB Output is correct
23 Correct 6 ms 19648 KB Output is correct
24 Correct 8 ms 20060 KB Output is correct
25 Correct 7 ms 19548 KB Output is correct
26 Correct 7 ms 19972 KB Output is correct
27 Correct 8 ms 20060 KB Output is correct
28 Correct 7 ms 20060 KB Output is correct
29 Correct 7 ms 20060 KB Output is correct
30 Correct 8 ms 20128 KB Output is correct
31 Correct 8 ms 20056 KB Output is correct
32 Correct 10 ms 20316 KB Output is correct
33 Correct 425 ms 97476 KB Output is correct
34 Correct 267 ms 63912 KB Output is correct
35 Correct 410 ms 94884 KB Output is correct
36 Correct 258 ms 64028 KB Output is correct
37 Correct 186 ms 44968 KB Output is correct
38 Correct 143 ms 40360 KB Output is correct
39 Correct 238 ms 59124 KB Output is correct
40 Correct 180 ms 50100 KB Output is correct
41 Correct 110 ms 50124 KB Output is correct
42 Correct 261 ms 49916 KB Output is correct
43 Correct 186 ms 40888 KB Output is correct
44 Correct 422 ms 123100 KB Output is correct
45 Correct 247 ms 78244 KB Output is correct
46 Correct 93 ms 40588 KB Output is correct
47 Correct 367 ms 65992 KB Output is correct
48 Correct 166 ms 50108 KB Output is correct
49 Correct 113 ms 49856 KB Output is correct
50 Correct 369 ms 71532 KB Output is correct
51 Correct 138 ms 49972 KB Output is correct
52 Correct 380 ms 67040 KB Output is correct
53 Correct 175 ms 50484 KB Output is correct
54 Correct 142 ms 59376 KB Output is correct
55 Correct 313 ms 67428 KB Output is correct
56 Correct 241 ms 68036 KB Output is correct
57 Correct 243 ms 68920 KB Output is correct
58 Correct 274 ms 67872 KB Output is correct
59 Correct 282 ms 67776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 19032 KB Output is correct
2 Correct 3 ms 19032 KB Output is correct
3 Correct 4 ms 19288 KB Output is correct
4 Correct 3 ms 19036 KB Output is correct
5 Correct 10 ms 20508 KB Output is correct
6 Correct 8 ms 19804 KB Output is correct
7 Correct 7 ms 19544 KB Output is correct
8 Correct 9 ms 20572 KB Output is correct
9 Correct 9 ms 19800 KB Output is correct
10 Correct 8 ms 19548 KB Output is correct
11 Correct 6 ms 19288 KB Output is correct
12 Correct 8 ms 19804 KB Output is correct
13 Correct 6 ms 19800 KB Output is correct
14 Correct 8 ms 19548 KB Output is correct
15 Correct 7 ms 19544 KB Output is correct
16 Correct 10 ms 20828 KB Output is correct
17 Correct 8 ms 20100 KB Output is correct
18 Correct 5 ms 19292 KB Output is correct
19 Correct 8 ms 20072 KB Output is correct
20 Correct 7 ms 19548 KB Output is correct
21 Correct 6 ms 19656 KB Output is correct
22 Correct 7 ms 20060 KB Output is correct
23 Correct 6 ms 19648 KB Output is correct
24 Correct 8 ms 20060 KB Output is correct
25 Correct 7 ms 19548 KB Output is correct
26 Correct 7 ms 19972 KB Output is correct
27 Correct 8 ms 20060 KB Output is correct
28 Correct 7 ms 20060 KB Output is correct
29 Correct 7 ms 20060 KB Output is correct
30 Correct 8 ms 20128 KB Output is correct
31 Correct 8 ms 20056 KB Output is correct
32 Correct 10 ms 20316 KB Output is correct
33 Correct 425 ms 97476 KB Output is correct
34 Correct 267 ms 63912 KB Output is correct
35 Correct 410 ms 94884 KB Output is correct
36 Correct 258 ms 64028 KB Output is correct
37 Correct 186 ms 44968 KB Output is correct
38 Correct 143 ms 40360 KB Output is correct
39 Correct 238 ms 59124 KB Output is correct
40 Correct 180 ms 50100 KB Output is correct
41 Correct 110 ms 50124 KB Output is correct
42 Correct 261 ms 49916 KB Output is correct
43 Correct 186 ms 40888 KB Output is correct
44 Correct 422 ms 123100 KB Output is correct
45 Correct 247 ms 78244 KB Output is correct
46 Correct 93 ms 40588 KB Output is correct
47 Correct 367 ms 65992 KB Output is correct
48 Correct 166 ms 50108 KB Output is correct
49 Correct 113 ms 49856 KB Output is correct
50 Correct 369 ms 71532 KB Output is correct
51 Correct 138 ms 49972 KB Output is correct
52 Correct 380 ms 67040 KB Output is correct
53 Correct 175 ms 50484 KB Output is correct
54 Correct 142 ms 59376 KB Output is correct
55 Correct 313 ms 67428 KB Output is correct
56 Correct 241 ms 68036 KB Output is correct
57 Correct 243 ms 68920 KB Output is correct
58 Correct 274 ms 67872 KB Output is correct
59 Correct 282 ms 67776 KB Output is correct
60 Runtime error 319 ms 524288 KB Execution killed with signal 9
61 Halted 0 ms 0 KB -