답안 #802855

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
802855 2023-08-02T15:12:34 Z thimote75 Worst Reporter 4 (JOI21_worst_reporter4) C++14
14 / 100
2000 ms 84744 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;
using Point = pair<int, int>;
using idata = vector<int>;

struct Treap {
    vector<Point> points;

    void insert( Point point ) {
        points.push_back(point);
    }
    int query (int x) {
        int res = 0;
        for (Point &point : points) if (x >= point.first) res += point.second;

        return res;
    }
    void chmin (int until) {
        sort(points.begin(), points.end());

        int res = 0;
        int idx = 0;
        int lp  = -1;
        for (Point &point : points) {
            if (res + point.second > until) {
                idx ++;
                point.second = until - res;
                break ;
            }

            res += point.second;
            idx ++;
        }

        if (idx == points.size()) return ;

        points.resize(idx);
        if (res == until) return ;
    }

    Treap cut (int position) {
        Treap other;

        vector<Point> local;
        for (Point & point : points) {
            if (point.first <= position) local.push_back(point);
            else other.insert(point);
        }

        points = local;

        return other;
    }

    void show () {
        sort(points.begin(), points.end());

        for (Point &point : points)
            cout << point.first << ": " << point.second << endl;
    }
    int size () { return points.size(); }
    void swap (Treap &other) { points.swap(other.points); }
};

void compile (Treap &treap, int H_i, int C_i) {
    int chmin_left = treap.query( H_i );
    Treap right = treap.cut(H_i);

    right.insert({ H_i + 1, C_i });

    treap.insert({ - 1e9, C_i });
    treap.chmin( chmin_left );

    for (Point &point : right.points) treap.insert(point);
}
void merge (Treap &target, Treap &other) {
    if (target.size() < other.size())
        target.swap(other);
    
    for (Point point : other.points)
        target.insert(point);
}

vector<Treap> treapArray;

idata A, H, C;

signed main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N;
    cin >> N;

    treapArray.resize(N);

    A.resize(N); H.resize(N); C.resize(N);
    for (int i = 0; i < N; i ++) {
        cin >> A[i] >> H[i] >> C[i];
        A[i] --;

        if ((i != 0 && A[i] > i - 1) || (i == 0 && A[i] != 0)) return 0;
    }
    
    for (int i = N - 1; i >= 0; i --) {
        compile(treapArray[i], H[i], C[i]);

        if (i == 0) continue ;
        merge(treapArray[A[i]], treapArray[i]);
    }

    cout << treapArray[0].query(1) << endl;
}

Compilation message

worst_reporter2.cpp: In member function 'void Treap::chmin(long long int)':
worst_reporter2.cpp:38:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         if (idx == points.size()) return ;
      |             ~~~~^~~~~~~~~~~~~~~~
worst_reporter2.cpp:26:13: warning: unused variable 'lp' [-Wunused-variable]
   26 |         int lp  = -1;
      |             ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 5 ms 1952 KB Output is correct
6 Correct 6 ms 1748 KB Output is correct
7 Correct 5 ms 1976 KB Output is correct
8 Correct 5 ms 1876 KB Output is correct
9 Correct 5 ms 1876 KB Output is correct
10 Correct 5 ms 1876 KB Output is correct
11 Correct 4 ms 2132 KB Output is correct
12 Correct 641 ms 1012 KB Output is correct
13 Correct 693 ms 992 KB Output is correct
14 Correct 296 ms 932 KB Output is correct
15 Correct 300 ms 1004 KB Output is correct
16 Correct 5 ms 2388 KB Output is correct
17 Correct 5 ms 2332 KB Output is correct
18 Correct 4 ms 2640 KB Output is correct
19 Correct 371 ms 1060 KB Output is correct
20 Correct 441 ms 1308 KB Output is correct
21 Correct 414 ms 1340 KB Output is correct
22 Correct 2 ms 1360 KB Output is correct
23 Correct 3 ms 1372 KB Output is correct
24 Correct 571 ms 1212 KB Output is correct
25 Correct 659 ms 1372 KB Output is correct
26 Correct 944 ms 1212 KB Output is correct
27 Correct 127 ms 1312 KB Output is correct
28 Correct 286 ms 1440 KB Output is correct
29 Correct 486 ms 1028 KB Output is correct
30 Correct 718 ms 1300 KB Output is correct
31 Correct 705 ms 1196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 5 ms 1952 KB Output is correct
6 Correct 6 ms 1748 KB Output is correct
7 Correct 5 ms 1976 KB Output is correct
8 Correct 5 ms 1876 KB Output is correct
9 Correct 5 ms 1876 KB Output is correct
10 Correct 5 ms 1876 KB Output is correct
11 Correct 4 ms 2132 KB Output is correct
12 Correct 641 ms 1012 KB Output is correct
13 Correct 693 ms 992 KB Output is correct
14 Correct 296 ms 932 KB Output is correct
15 Correct 300 ms 1004 KB Output is correct
16 Correct 5 ms 2388 KB Output is correct
17 Correct 5 ms 2332 KB Output is correct
18 Correct 4 ms 2640 KB Output is correct
19 Correct 371 ms 1060 KB Output is correct
20 Correct 441 ms 1308 KB Output is correct
21 Correct 414 ms 1340 KB Output is correct
22 Correct 2 ms 1360 KB Output is correct
23 Correct 3 ms 1372 KB Output is correct
24 Correct 571 ms 1212 KB Output is correct
25 Correct 659 ms 1372 KB Output is correct
26 Correct 944 ms 1212 KB Output is correct
27 Correct 127 ms 1312 KB Output is correct
28 Correct 286 ms 1440 KB Output is correct
29 Correct 486 ms 1028 KB Output is correct
30 Correct 718 ms 1300 KB Output is correct
31 Correct 705 ms 1196 KB Output is correct
32 Correct 6 ms 2028 KB Output is correct
33 Correct 229 ms 80052 KB Output is correct
34 Correct 239 ms 78592 KB Output is correct
35 Correct 239 ms 79484 KB Output is correct
36 Correct 237 ms 81236 KB Output is correct
37 Correct 244 ms 82320 KB Output is correct
38 Correct 175 ms 84744 KB Output is correct
39 Execution timed out 2059 ms 15376 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 5 ms 1952 KB Output is correct
6 Correct 6 ms 1748 KB Output is correct
7 Correct 5 ms 1976 KB Output is correct
8 Correct 5 ms 1876 KB Output is correct
9 Correct 5 ms 1876 KB Output is correct
10 Correct 5 ms 1876 KB Output is correct
11 Correct 4 ms 2132 KB Output is correct
12 Correct 641 ms 1012 KB Output is correct
13 Correct 693 ms 992 KB Output is correct
14 Correct 296 ms 932 KB Output is correct
15 Correct 300 ms 1004 KB Output is correct
16 Correct 5 ms 2388 KB Output is correct
17 Correct 5 ms 2332 KB Output is correct
18 Correct 4 ms 2640 KB Output is correct
19 Correct 371 ms 1060 KB Output is correct
20 Correct 441 ms 1308 KB Output is correct
21 Correct 414 ms 1340 KB Output is correct
22 Correct 2 ms 1360 KB Output is correct
23 Correct 3 ms 1372 KB Output is correct
24 Correct 571 ms 1212 KB Output is correct
25 Correct 659 ms 1372 KB Output is correct
26 Correct 944 ms 1212 KB Output is correct
27 Correct 127 ms 1312 KB Output is correct
28 Correct 286 ms 1440 KB Output is correct
29 Correct 486 ms 1028 KB Output is correct
30 Correct 718 ms 1300 KB Output is correct
31 Correct 705 ms 1196 KB Output is correct
32 Correct 6 ms 2028 KB Output is correct
33 Correct 229 ms 80052 KB Output is correct
34 Correct 239 ms 78592 KB Output is correct
35 Correct 239 ms 79484 KB Output is correct
36 Correct 237 ms 81236 KB Output is correct
37 Correct 244 ms 82320 KB Output is correct
38 Correct 175 ms 84744 KB Output is correct
39 Execution timed out 2059 ms 15376 KB Time limit exceeded
40 Halted 0 ms 0 KB -