Submission #1021725

#TimeUsernameProblemLanguageResultExecution timeMemory
1021725NoLoveBitaro’s Party (JOI18_bitaro)C++14
100 / 100
825 ms147268 KiB
/** * author : Lăng Trọng Đạt * created: 12-07-2024 **/ #include <bits/stdc++.h> using namespace std; #ifndef LANG_DAT #define db(...) ; #endif // LANG_DAT #define f first #define se second #define pb push_back #define all(v) (v).begin(), (v).end() using pii = pair<int, int>; using vi = vector<int>; #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++) void mx(int& a, int b) { if (b > a) a = b; } void mi(int& a, int b) { if (b < a) a = b; } #define si(x) (int)(x.size()) const int MAXN = 1e5 + 5; const int B = 100; vector<int> adj[MAXN]; int n, m, q, a, b; vector<pii> len[MAXN]; // {end node, longest length} bool block[MAXN]; int32_t main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> m >> q; FOR(i, 1, m) { cin >> a >> b; adj[b].push_back(a); } vector<int> pos(n + 1, -1); FOR(v, 1, n) { len[v].push_back({v, 0}); for (int u : adj[v]) { for (auto[a, b] : len[u]) { if (pos[a] != -1) mx(len[v][pos[a]].se, b + 1); else len[v].push_back({a, b + 1}); } sort(all(len[v]), [](pii& a, pii& b) -> bool {return a.se > b.se;}); while (si(len[v]) > B + 5) {pos[len[v].back().f] = -1; len[v].pop_back(); } FOR(id, 0, si(len[v]) - 1) { pos[len[v][id].f] = id; } } FOR(id, 0, si(len[v]) - 1) { pos[len[v][id].f] = -1; } } vector<int> dp(n + 1, -1); FOR(i, 1, q) { int source, t; cin >> source >> t; // db(source, t) vector<int> c(t); for (int& v : c) { cin >> v; block[v] = 1; } int ans = -1; if (t > B) { FOR(v, 1, source) { for (int u : adj[v]) { if (dp[u] != -1) mx(dp[v], dp[u] + 1); } if (!block[v]) mx(dp[v], 0); if (v == source) { ans = dp[v]; break; } } fill(dp.begin(), dp.begin() + source + 1, -1); } else { for (auto[u, l] : len[source]) { if (!block[u]) { ans = l; break; } } } cout << (ans < 0 ? -1 : ans) << "\n"; for (int v : c) { block[v] = 0; } } }

Compilation message (stderr)

bitaro.cpp: In function 'int32_t main()':
bitaro.cpp:16:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
      |                               ^
bitaro.cpp:34:5: note: in expansion of macro 'FOR'
   34 |     FOR(i, 1, m) {
      |     ^~~
bitaro.cpp:16:31: warning: unnecessary parentheses in declaration of 'v' [-Wparentheses]
   16 | #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
      |                               ^
bitaro.cpp:40:5: note: in expansion of macro 'FOR'
   40 |     FOR(v, 1, n) {
      |     ^~~
bitaro.cpp:43:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   43 |             for (auto[a, b] : len[u]) {
      |                      ^
bitaro.cpp:16:31: warning: unnecessary parentheses in declaration of 'id' [-Wparentheses]
   16 | #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
      |                               ^
bitaro.cpp:49:13: note: in expansion of macro 'FOR'
   49 |             FOR(id, 0, si(len[v]) - 1) {
      |             ^~~
bitaro.cpp:16:31: warning: unnecessary parentheses in declaration of 'id' [-Wparentheses]
   16 | #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
      |                               ^
bitaro.cpp:53:9: note: in expansion of macro 'FOR'
   53 |         FOR(id, 0, si(len[v]) - 1) {
      |         ^~~
bitaro.cpp:16:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
      |                               ^
bitaro.cpp:59:5: note: in expansion of macro 'FOR'
   59 |     FOR(i, 1, q) {
      |     ^~~
bitaro.cpp:16:31: warning: unnecessary parentheses in declaration of 'v' [-Wparentheses]
   16 | #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
      |                               ^
bitaro.cpp:70:13: note: in expansion of macro 'FOR'
   70 |             FOR(v, 1, source) {
      |             ^~~
bitaro.cpp:83:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   83 |             for (auto[u, l] : len[source]) {
      |                      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...