Submission #567300

#TimeUsernameProblemLanguageResultExecution timeMemory
567300shrimbBitaro’s Party (JOI18_bitaro)C++17
14 / 100
2003 ms177272 KiB
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2,fma")

#include"bits/stdc++.h"
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;

#define int long long
#define endl '\n'
#define mod 1000000007
//\
#define mod 1686876991

const int maxn = 100001;
const int sq = 101;

vector<int> adj[maxn], radj[maxn];

int n, m, q;

vector<pair<int,int>> dp[maxn];
int dp2[maxn];
int c[maxn];
bitset<maxn> rem, inserted;

signed main () {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m >> q;

    for (int i = 0 ; i < m ; i++) {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        radj[b].push_back(a);
    }

    for (int i = 1 ; i <= n ; i++) {
        dp[i].push_back({0, i});
    }
    for (int i = 1 ; i <= n ; i++) {
        vector<pair<int,int>> v = dp[i];
        for (int j : radj[i]) {
            v.insert(v.end(), dp[j].begin(), dp[j].end());
        }
        for (int j = 1 ; j < v.size()  ; j++) v[j].first++;
        sort(v.begin(), v.end(), greater<pair<int,int>>());

        // cerr << v.size() << endl;
        dp[i].resize(min(sq, (int)v.size()));
        for (int idx = 0, j = 0 ; j < v.size() and idx < sq ; j++) {
            if (inserted[v[j].second]) continue;
            inserted[v[j].second] = 1;
            dp[i][idx] = v[j];
            idx++;
        }
        for (int j = 0 ; j < v.size() ; j++) inserted[v[j].second] = 0;
        // cerr << "here\n";
    }

    for (int i = 0 ; i < q ; i++) {
        int t, y;
        cin >> t >> y;
        for (int j = 0 ; j < y ; j++) cin >> c[j], rem[c[j]] = 1;
        if (y < sq - 1) {
            for (auto j : dp[t]) {
                if (!rem[j.second]) {
                    cout << j.first << endl;
                    goto good;
                }
            }
            cout << -1 << endl;
            good:;
        }
        else {
            for (int j = 1 ; j <= t ; j++) {
                dp2[j] = (rem[j] ? -1e9 : 0);
                for (int k : radj[j]) dp2[j] = max(dp2[j], dp2[k] + 1);
            }
            if (dp2[t] < 0) cout << -1 << endl;
            else cout << dp2[t] << endl;
        }
        for (int j = 0 ; j < y ; j++) rem[c[j]] = 0;
    }
}

Compilation message (stderr)

bitaro.cpp:17:1: warning: multi-line comment [-Wcomment]
   17 | //\
      | ^
bitaro.cpp: In function 'int main()':
bitaro.cpp:51:28: 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]
   51 |         for (int j = 1 ; j < v.size()  ; j++) v[j].first++;
      |                          ~~^~~~~~~~~~
bitaro.cpp:56:37: 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]
   56 |         for (int idx = 0, j = 0 ; j < v.size() and idx < sq ; j++) {
      |                                   ~~^~~~~~~~~~
bitaro.cpp:62:28: 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]
   62 |         for (int j = 0 ; j < v.size() ; j++) inserted[v[j].second] = 0;
      |                          ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...