Submission #745614

#TimeUsernameProblemLanguageResultExecution timeMemory
745614mars4Bitaro’s Party (JOI18_bitaro)C++17
100 / 100
1231 ms516932 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ff first #define ss second #define ll int64_t #define ld long double #define nl cout<<"\n" #define i128 __int128_t #define all(v) v.begin(),v.end() #define mset(a,v) memset((a),(v),sizeof(a)) #define forn(i,a,b) for(int64_t i=int64_t(a);i<int64_t(b);++i) #define forb(i,a,b) for(int64_t i=int64_t(a);i>=int64_t(b);--i) #define fastio() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define mod 1'000'000'007 #define mod2 998'244'353 #define inf 1'000'000'000'000'007 #define pi 3.14159265358979323846 template<class key,class cmp=std::less<key>> using ordered_set=tree<key,null_type,cmp,rb_tree_tag,tree_order_statistics_node_update>; template<class L,class R> ostream& operator<<(ostream& out,pair<L,R> &p) {return out<<"("<<p.ff<<", "<<p.ss<<")";} template<class T> ostream& operator<<(ostream& out,vector<T> &v) {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";} template<class T> ostream& operator<<(ostream& out,deque<T> &v) {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";} template<class T> ostream& operator<<(ostream& out,set<T> &s) {out<<"{";for(auto it=s.begin();it!=s.end();++it){if(it!=s.begin())out<<", ";out<<*it;}return out<<"}";} template<class T> ostream& operator<<(ostream& out,ordered_set<T> &s) {out<<"{";for(auto it=s.begin();it!=s.end();++it){if(it!=s.begin())out<<", ";out<<*it;}return out<<"}";} template<class L,class R> ostream& operator<<(ostream& out,map<L,R> &m) {out<<"{";for(auto it=m.begin();it!=m.end();++it){if(it!=m.begin())out<<", ";out<<*it;}return out<<"}";} void dbg_out() {cerr<<"]\n";} template<typename Head,typename... Tail> void dbg_out(Head H,Tail... T) {cerr<<H;if(sizeof...(Tail))cerr<<", ";dbg_out(T...);} #ifdef LOCAL #define dbg(...) cerr<<"["<<#__VA_ARGS__<<"] = [",dbg_out(__VA_ARGS__) #else #define dbg(...) #endif //---------------------------------mars4--------------------------------- int main() { fastio(); ll z,n,m,t,k,i,j,l,d,h,r; ll q; const ll B=200; cin>>n>>m>>q; vector<vector<ll>> v(n); vector<vector<pair<ll,ll>>> dist(n); forn(i,0,m) { cin>>l>>r; l--,r--; v[r].push_back(l); } vector<ll> visited(n,-1); vector<ll> pos(n); forn(i,0,n) { dist[i].push_back({0,i}); for(ll nxt:v[i]) { for(auto [d,ind]:dist[nxt]) { if(visited[ind]!=i) { pos[ind]=(ll)dist[i].size(); visited[ind]=i; dist[i].push_back({d+1,ind}); } else if(dist[i][pos[ind]].ff<d+1) { dist[i][pos[ind]].ff=d+1; } } } sort(all(dist[i]),greater<pair<ll,ll>>()); h=(ll)dist[i].size(); if(h>B) { dist[i].resize(B); } } vector<ll> mark(n,-1); vector<ll> len(n); forn(i,0,q) { ll town; cin>>town>>k; town--; forn(j,0,k) { cin>>r; r--; mark[r]=i; } ll ans=-1; if(k<B) { for(auto [d,ind]:dist[town]) { if(mark[ind]!=i) { ans=d; break; } } } else { forn(j,0,town+1) { len[j]=(mark[j]==i)?-inf:0; for(ll nxt:v[j]) { len[j]=max(len[j],len[nxt]+1); } } ans=max(len[town],(ll)-1); } cout<<ans<<"\n"; } cerr<<"\nTime elapsed: "<<1000*clock()/CLOCKS_PER_SEC<<"ms\n"; return 0; }

Compilation message (stderr)

bitaro.cpp: In function 'int main()':
bitaro.cpp:49:5: warning: unused variable 'z' [-Wunused-variable]
   49 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |     ^
bitaro.cpp:49:11: warning: unused variable 't' [-Wunused-variable]
   49 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |           ^
bitaro.cpp:49:15: warning: unused variable 'i' [-Wunused-variable]
   49 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |               ^
bitaro.cpp:49:17: warning: unused variable 'j' [-Wunused-variable]
   49 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |                 ^
bitaro.cpp:49:21: warning: unused variable 'd' [-Wunused-variable]
   49 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...