Submission #935852

#TimeUsernameProblemLanguageResultExecution timeMemory
935852panBitaro’s Party (JOI18_bitaro)C++17
100 / 100
929 ms148304 KiB
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //#include "bits_stdc++.h" #define f first #define s second #define pb push_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define input(x) scanf("%d", &x); #define input2(x, y) scanf("%d%d", &x, &y); #define input3(x, y, z) scanf("%d%d%d", &x, &y, &z); #define input4(x, y, z, a) scanf("%d%d%d%d", &x, &y, &z, &a); #define print(x, y) printf("%d%c", x, y); #define show(x) cerr << #x << " is " << x << endl; #define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl; #define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl; #define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end()); using namespace std; //using namespace __gnu_pbds; //#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> //#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> typedef int ll; typedef long double ld; typedef pair<ld, ll> pd; typedef pair<string, ll> psl; typedef pair<ll, ll> pi; typedef pair<ll, pi> pii; ll n, m, q, x, y, bound = 100; vector<ll> radj[100005]; bool ban[100005]; vector<pi> maxdist[100005]; ll dist[100005][2]; void initsqrt() // O(n * sqrt(n)) { for (ll i=0; i<n; ++i) { vector<ll> list; list.pb(i); maxdist[i].pb(mp(0, i)); dist[i][0] = 0; dist[i][1] = i; for (ll u: radj[i]) { for (pi x: maxdist[u]) { if (dist[x.s][1]!=i) { list.pb(x.s); dist[x.s][0] = x.f+1; dist[x.s][1] = i; } else { dist[x.s][0] = max(dist[x.s][0], x.f+1); } } } for (ll u: list) maxdist[i].pb(mp(dist[u][0], u)); sort(maxdist[i].begin(), maxdist[i].end(), greater<pi>()); while (maxdist[i].size()>bound) maxdist[i].pop_back(); } } ll dp(ll t) // O(n) { ll dp[n]; fill(dp, dp+n, 0); for (ll i=0; i<=t; ++i) { for (ll u: radj[i]) dp[i] = max(dp[i], dp[u]+1); if (ban[i]&& dp[i]==0 ) dp[i] = -1; } return dp[t]; } int main() { input3(n, m, q); for (ll i=0; i<m; ++i) { input2(x, y); x--; y--; radj[y].pb(x); } initsqrt(); while (q--) { ll t, y, temp; input2(t, y); t--; fill(ban, ban+n, 0); for (ll i=0; i<y; ++i) {input(temp);temp--; ban[temp] = true;} if (y>=bound) {print(dp(t), '\n'); continue;} ll ans = -1; for (pi u: maxdist[t]) { //show(u.s); if (ban[u.s]) continue; ans = u.f; break; } print(ans, '\n'); } return 0; }

Compilation message (stderr)

bitaro.cpp: In function 'void initsqrt()':
bitaro.cpp:63:27: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'int'} [-Wsign-compare]
   63 |   while (maxdist[i].size()>bound) maxdist[i].pop_back();
      |          ~~~~~~~~~~~~~~~~~^~~~~~
bitaro.cpp: In function 'int main()':
bitaro.cpp:13:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define input3(x, y, z) scanf("%d%d%d", &x, &y, &z);
      |                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:81:2: note: in expansion of macro 'input3'
   81 |  input3(n, m, q);
      |  ^~~~~~
bitaro.cpp:12:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define input2(x, y) scanf("%d%d", &x, &y);
      |                      ~~~~~^~~~~~~~~~~~~~~~
bitaro.cpp:84:3: note: in expansion of macro 'input2'
   84 |   input2(x, y);
      |   ^~~~~~
bitaro.cpp:12:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define input2(x, y) scanf("%d%d", &x, &y);
      |                      ~~~~~^~~~~~~~~~~~~~~~
bitaro.cpp:92:3: note: in expansion of macro 'input2'
   92 |   input2(t, y);
      |   ^~~~~~
bitaro.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | #define input(x) scanf("%d", &x);
      |                  ~~~~~^~~~~~~~~~
bitaro.cpp:95:27: note: in expansion of macro 'input'
   95 |   for (ll i=0; i<y; ++i) {input(temp);temp--; ban[temp] = true;}
      |                           ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...