Submission #707367

#TimeUsernameProblemLanguageResultExecution timeMemory
707367EthanKim8683Bitaro’s Party (JOI18_bitaro)C++17
7 / 100
1762 ms524288 KiB
#include<bits/stdc++.h> using namespace std; using I=int; const I N=100000; const I MIN=-1e9; vector<I>adjs[N]; set<pair<I,I>>tops[N]; set<I>curs; I inds[N]; I dp[N]; I main(){ cin.tie(0)->sync_with_stdio(0); I n,m,q;cin>>n>>m>>q; for(I i=0;i<m;i++){ I s,e;cin>>s>>e,s--,e--; adjs[s].push_back(e),inds[e]++; } I siz=sqrt(n); for(I i=0;i<n;i++)tops[i].insert({0,i}); for(I i=0;i<n;i++)for(auto j:adjs[i])for(auto[dis,k]:tops[i]){ tops[j].insert({dis-1,k}); if(tops[j].size()>siz)tops[j].erase(prev(tops[j].end())); } while(q--){ I t,y;cin>>t>>y,t--; curs.clear(); for(I i=0;i<y;i++){I c;cin>>c,curs.insert(c-1);} I res=MIN; for(auto[dis,i]:tops[t])if(!curs.count(i)){res=-dis;break;} if(res!=MIN){printf("%i\n",res);continue;} if(tops[t].size()==inds[t]+1){printf("-1\n");continue;} fill_n(dp,t+1,0); for(auto c:curs)dp[c]=MIN; for(I i=0;i<t;i++){ if(dp[i]==MIN)continue; for(auto j:adjs[i])if(j<=t)dp[j]=max(dp[j],dp[i]+1); } printf("%i\n",dp[t]==MIN?-1:dp[t]); } }

Compilation message (stderr)

bitaro.cpp: In function 'I main()':
bitaro.cpp:22:22: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'I' {aka 'int'} [-Wsign-compare]
   22 |     if(tops[j].size()>siz)tops[j].erase(prev(tops[j].end()));
      |        ~~~~~~~~~~~~~~^~~~
bitaro.cpp:31:22: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'I' {aka 'int'} [-Wsign-compare]
   31 |     if(tops[t].size()==inds[t]+1){printf("-1\n");continue;}
      |        ~~~~~~~~~~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...