Submission #979573

#TimeUsernameProblemLanguageResultExecution timeMemory
979573saayan007Bitaro’s Party (JOI18_bitaro)C++17
14 / 100
2102 ms12628 KiB
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
#define repd(i, a, b) for(int (i) = (a); i >= (b); --i)

#define em emplace
#define eb emplace_back

#define pi pair<int, int>
#define fr first
#define sc second
#define mp make_pair

const char nl = '\n';
const int mod = 1e9 + 7;
const int inf = 1e17;

int better(int x, int y) {
    if(x == -1) return y;
    return max(x, y);
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m, q;
    cin >> n >> m >> q;
    vector<int> adj[n + 1];
    rep(i, 1, m) {
        int s, e;
        cin >> s >> e;
        adj[e].eb(s);
    }

    int dp[n + 1];
    set<int> busy;
    while(q--) {

        busy.clear();
        int tar;
        cin >> tar;
        int y; cin >> y;
        rep(i, 1, y) {
            int c; cin >> c;
            busy.insert(c);
        }

        int res = -1;
        rep(i, 1, tar) {
            dp[i] = -1;
            if(!busy.count(i)) dp[i] = 0;
            for(int j : adj[i]) {
                assert(j < i);
                if(dp[j] == -1) continue;
                dp[i] = better(dp[i], dp[j] + 1);
            }
        }
        cout << dp[tar] << nl;
    }
}

Compilation message (stderr)

bitaro.cpp: In function 'int32_t main()':
bitaro.cpp:5:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
bitaro.cpp:32:5: note: in expansion of macro 'rep'
   32 |     rep(i, 1, m) {
      |     ^~~
bitaro.cpp:5:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
bitaro.cpp:46:9: note: in expansion of macro 'rep'
   46 |         rep(i, 1, y) {
      |         ^~~
bitaro.cpp:5:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
bitaro.cpp:52:9: note: in expansion of macro 'rep'
   52 |         rep(i, 1, tar) {
      |         ^~~
bitaro.cpp:51:13: warning: unused variable 'res' [-Wunused-variable]
   51 |         int res = -1;
      |             ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...