Submission #1096182

# Submission time Handle Problem Language Result Execution time Memory
1096182 2024-10-04T04:08:16 Z Zero_OP Bitaro’s Party (JOI18_bitaro) C++14
14 / 100
1241 ms 427856 KB
#include "bits/stdc++.h"

using namespace std;

#define sz(v) (int)v.size()
#define all(v) begin(v), end(v)
#define compact(v) v.erase(unique(all(v)), end(v))

const int MAX = 1e5 + 5;
int SQRT = 350;

int n, m, q, f[MAX];
vector<int> rev[MAX];
vector<pair<int, int>> dp[MAX]; //[dist, u]
bool bad[MAX];

void insert(vector<pair<int, int>> &A, vector<pair<int, int>>& B){
    //B + 1

    vector<pair<int, int>> C;
    int i = 0, j = 0;
    while(i < sz(A) || j < sz(B)){
        if(i == sz(A)) C.push_back({B[j].first + 1, B[j].second}), ++j;
        else if(j == sz(B)) C.push_back(A[i++]);
        else if((A[i].first < B[j].first + 1) || (A[i].first == B[j].first + 1 && A[i].second > B[j].second)) C.push_back({B[j].first + 1, B[j].second}), ++j;
        else C.push_back(A[i++]);
    }

    compact(C);
    A = C;

    if(A.size() > SQRT + 1) A.resize(SQRT + 1);
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m >> q;
    for(int i = 0; i < m; ++i){
        int u, v;
        cin >> u >> v;
        rev[v].push_back(u);
    }

    SQRT = sqrt(n);
    for(int i = 1; i <= n; ++i){
        dp[i].push_back({0, i});
        for(int j : rev[i]){
            insert(dp[i], dp[j]);
        }
    }

//    for(int i = 1; i <= n; ++i){
//        cout << i << " :\n";
//        for(auto j : S[i]) cout << j.first << ' ' << j.second << '\n'; cout << '\n';
//    }

    while(q--){
        int t, y;
        cin >> t >> y;

        vector<int> nodes(y);
        for(int i = 0; i < y; ++i) cin >> nodes[i];

        for(int u : nodes) bad[u] = true;

        if(y > SQRT){
//            cout << "heavy\n";
            fill(f + 1, f + 1 + n, -1e9);
            f[t] = 0;

            for(int i = t; i > 0; --i){
                for(int j : rev[i]){
                    f[j] = max(f[j], f[i] + 1);
                }
            }

            int ans = -1;
            for(int i = t; i > 0; --i){
                if(!bad[i]) ans = max(ans, f[i]);
            }

            cout << ans << '\n';
        } else{
//            cout << "light\n";
            int ans = -1;
            for(auto u : dp[t]){
                if(!bad[u.second]){
                    ans = u.first;
                    break;
                }
            }

            if(ans == -1){
                cout << ans << '\n';
            } else{
                cout << ans << '\n';
            }
        }

        for(int u : nodes) bad[u] = false;
    }

    return 0;
}
/*


test 1 :
5 6 3
1 2
2 4
3 4
1 3
3 5
4 5
4 1 1
5 2 2 3
2 3 1 4 5

test 2 :
12 17 10
1 2
2 3
3 4
1 5
2 6
3 7
4 8
5 6
6 7
7 8
5 9
6 10
7 11
8 12
9 10
10 11
11 12
6 3 1 7 12
3 7 1 2 3 4 5 6 7
11 3 1 3 5
9 2 1 9
8 4 1 2 3 4
1 1 1
12 0
10 3 1 6 10
11 8 2 3 5 6 7 9 10 11
8 7 2 3 4 5 6 7 8

test 3 :
12 17 1
1 2
2 3
3 4
1 5
2 6
3 7
4 8
5 6
6 7
7 8
5 9
6 10
7 11
8 12
9 10
10 11
11 12
12 0
*/

Compilation message

bitaro.cpp: In function 'void insert(std::vector<std::pair<int, int> >&, std::vector<std::pair<int, int> >&)':
bitaro.cpp:32:17: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |     if(A.size() > SQRT + 1) A.resize(SQRT + 1);
      |        ~~~~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 5016 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 3 ms 4956 KB Output is correct
5 Correct 3 ms 5428 KB Output is correct
6 Correct 4 ms 5468 KB Output is correct
7 Correct 3 ms 5484 KB Output is correct
8 Correct 3 ms 5468 KB Output is correct
9 Correct 4 ms 5464 KB Output is correct
10 Correct 3 ms 5468 KB Output is correct
11 Correct 3 ms 5468 KB Output is correct
12 Correct 5 ms 5464 KB Output is correct
13 Correct 4 ms 5496 KB Output is correct
14 Correct 3 ms 5468 KB Output is correct
15 Correct 4 ms 5212 KB Output is correct
16 Correct 3 ms 5468 KB Output is correct
17 Correct 4 ms 5468 KB Output is correct
18 Correct 3 ms 5468 KB Output is correct
19 Correct 3 ms 5468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 5016 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 3 ms 4956 KB Output is correct
5 Correct 3 ms 5428 KB Output is correct
6 Correct 4 ms 5468 KB Output is correct
7 Correct 3 ms 5484 KB Output is correct
8 Correct 3 ms 5468 KB Output is correct
9 Correct 4 ms 5464 KB Output is correct
10 Correct 3 ms 5468 KB Output is correct
11 Correct 3 ms 5468 KB Output is correct
12 Correct 5 ms 5464 KB Output is correct
13 Correct 4 ms 5496 KB Output is correct
14 Correct 3 ms 5468 KB Output is correct
15 Correct 4 ms 5212 KB Output is correct
16 Correct 3 ms 5468 KB Output is correct
17 Correct 4 ms 5468 KB Output is correct
18 Correct 3 ms 5468 KB Output is correct
19 Correct 3 ms 5468 KB Output is correct
20 Correct 118 ms 8276 KB Output is correct
21 Correct 118 ms 8176 KB Output is correct
22 Correct 122 ms 8268 KB Output is correct
23 Correct 125 ms 8276 KB Output is correct
24 Correct 834 ms 265160 KB Output is correct
25 Correct 846 ms 278396 KB Output is correct
26 Correct 822 ms 276744 KB Output is correct
27 Correct 1024 ms 427496 KB Output is correct
28 Correct 1035 ms 427592 KB Output is correct
29 Correct 996 ms 427284 KB Output is correct
30 Correct 956 ms 426244 KB Output is correct
31 Correct 921 ms 402912 KB Output is correct
32 Correct 974 ms 426324 KB Output is correct
33 Correct 731 ms 242004 KB Output is correct
34 Correct 636 ms 198480 KB Output is correct
35 Correct 722 ms 240208 KB Output is correct
36 Correct 893 ms 339936 KB Output is correct
37 Correct 864 ms 298580 KB Output is correct
38 Correct 913 ms 340836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 5016 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 3 ms 4956 KB Output is correct
5 Correct 3 ms 5428 KB Output is correct
6 Correct 4 ms 5468 KB Output is correct
7 Correct 3 ms 5484 KB Output is correct
8 Correct 3 ms 5468 KB Output is correct
9 Correct 4 ms 5464 KB Output is correct
10 Correct 3 ms 5468 KB Output is correct
11 Correct 3 ms 5468 KB Output is correct
12 Correct 5 ms 5464 KB Output is correct
13 Correct 4 ms 5496 KB Output is correct
14 Correct 3 ms 5468 KB Output is correct
15 Correct 4 ms 5212 KB Output is correct
16 Correct 3 ms 5468 KB Output is correct
17 Correct 4 ms 5468 KB Output is correct
18 Correct 3 ms 5468 KB Output is correct
19 Correct 3 ms 5468 KB Output is correct
20 Correct 118 ms 8276 KB Output is correct
21 Correct 118 ms 8176 KB Output is correct
22 Correct 122 ms 8268 KB Output is correct
23 Correct 125 ms 8276 KB Output is correct
24 Correct 834 ms 265160 KB Output is correct
25 Correct 846 ms 278396 KB Output is correct
26 Correct 822 ms 276744 KB Output is correct
27 Correct 1024 ms 427496 KB Output is correct
28 Correct 1035 ms 427592 KB Output is correct
29 Correct 996 ms 427284 KB Output is correct
30 Correct 956 ms 426244 KB Output is correct
31 Correct 921 ms 402912 KB Output is correct
32 Correct 974 ms 426324 KB Output is correct
33 Correct 731 ms 242004 KB Output is correct
34 Correct 636 ms 198480 KB Output is correct
35 Correct 722 ms 240208 KB Output is correct
36 Correct 893 ms 339936 KB Output is correct
37 Correct 864 ms 298580 KB Output is correct
38 Correct 913 ms 340836 KB Output is correct
39 Correct 825 ms 266064 KB Output is correct
40 Correct 857 ms 277880 KB Output is correct
41 Correct 829 ms 278300 KB Output is correct
42 Correct 886 ms 270652 KB Output is correct
43 Correct 845 ms 271952 KB Output is correct
44 Correct 139 ms 9552 KB Output is correct
45 Correct 125 ms 8784 KB Output is correct
46 Correct 225 ms 8528 KB Output is correct
47 Correct 142 ms 8404 KB Output is correct
48 Correct 120 ms 8180 KB Output is correct
49 Correct 1241 ms 427856 KB Output is correct
50 Incorrect 1047 ms 426072 KB Output isn't correct
51 Halted 0 ms 0 KB -