Submission #47800

#TimeUsernameProblemLanguageResultExecution timeMemory
47800Just_Solve_The_ProblemBitaro’s Party (JOI18_bitaro)C++11
0 / 100
26 ms11552 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define ll long long #define pii pair < int, int > #define fr first #define sc second #define mk make_pair #define sz(s) (int)s.size() #define all(s) s.begin(), s.end() #define ok puts("ok"); #define whatis(x) cerr << #x << " = " << x << endl; #define pause system("pause"); #define random (rand() ^ (rand() << 15)) const int N = (int)1e5 + 7; const int inf = (int)1e9 + 7; int sq = 300; int n, m, q; vector < int > gr[N], rgr[N]; vector < pii > dp[N]; bool bad[N]; vector < pii > mergevector(vector < pii > v1, vector < pii > v2) { vector < pii > ret; int c1, c2; c1 = c2 = 0; while (c1 < sz(v1) && c2 < sz(v2) && sz(ret) < sq) { int val1 = v1[c1].fr; int val2 = v2[c2].fr + 1; if (val1 > val2) { ret.pb(mk(val1, v1[c1].sc)); c1++; } else { ret.pb(mk(val2, v2[c2].sc)); c2++; } } while (sz(ret) < sq && c1 < sz(v1)) { ret.pb(v1[c1++]); } while (sz(ret) < sq && c2 < sz(v2)) { ret.pb(v2[c2++]); } return ret; } int solve(int v) { vector < int > dp1; dp1.resize(n + 1, -inf); dp1[v] = 0; int ret = -1; if (!bad[v]) ret = 0; for (int i = v; i > 0; i--) { for (int to : gr[i]) { dp1[i] = max(dp1[i], dp1[to] + 1); } if (!bad[i]) { ret = max(ret, dp1[i]); } } return ret; } main() { scanf("%d %d %d", &n, &m, &q); for (int i = 1; i <= m; i++) { int u, v; scanf("%d %d", &u, &v); gr[u].pb(v); rgr[v].pb(u); } for (int i = 1; i <= n; i++) { dp[i].pb(mk(0, i)); for (int to : rgr[i]) { dp[i] = mergevector(dp[i], dp[to]); } } while (q--) { int t, y; scanf("%d %d", &t, &y); vector < int > v; for (int i = 1; i <= y; i++) { int x; scanf("%d", &x); bad[x] = 1; v.pb(x); } int ans = -1; if (y < sq - 1) { ans = solve(t); } else { for (auto to : dp[t]) { if (bad[to.sc]) continue; ans = max(ans, to.fr); } } printf("%d\n", ans); for (int to : v) { bad[to] = 0; } } }

Compilation message (stderr)

bitaro.cpp:69:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
bitaro.cpp: In function 'int main()':
bitaro.cpp:70:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &n, &m, &q);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &u, &v);
     ~~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:85:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &t, &y);
     ~~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:89:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d", &x);
       ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...