Submission #979211

#TimeUsernameProblemLanguageResultExecution timeMemory
979211saayan007Bitaro’s Party (JOI18_bitaro)C++17
14 / 100
2012 ms10672 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[s].eb(e);
    }

    while(q--) {
        bool busy[n + 1] = {};
        int dp[n + 1];
        rep(i, 1, n) dp[i] = -1;

        int tar;
        cin >> tar;
        /* cout << tar << ' '; */
        int y; cin >> y;
        /* cout << y << ' '; */
        while(y--) {
            int c; cin >> c;
            busy[c] = 1;
            /* cout << c << ' '; */
        }
        /* cout << nl; */

        int res = -1;
        dp[tar] = 0;
        repd(i, tar, 1) {
            for(int j : adj[i]) {
                if(j > tar) continue;
                if(j == tar) dp[i] = better(dp[i], 0);
                if(dp[j] == -1) continue;
                dp[i] = better(dp[i], dp[j] + 1);
            }
            if(busy[i]) continue;
            res = better(res, dp[i]);
        }
        cout << res << 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:41:9: note: in expansion of macro 'rep'
   41 |         rep(i, 1, n) dp[i] = -1;
      |         ^~~
bitaro.cpp:6:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define repd(i, a, b) for(int (i) = (a); i >= (b); --i)
      |                               ^
bitaro.cpp:57:9: note: in expansion of macro 'repd'
   57 |         repd(i, tar, 1) {
      |         ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...