Submission #888056

#TimeUsernameProblemLanguageResultExecution timeMemory
888056PM1Bitaro’s Party (JOI18_bitaro)C++17
100 / 100
657 ms214608 KiB
#include <bits/stdc++.h> using namespace std; #define fr first #define sc second const int mxn=1e5+5,sq=130; int n,m,q,mark[mxn]; vector<int>v[mxn]; vector<pair<int,int> >pre[mxn]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>m>>q; for(int i=1;i<=m;i++){ int x,y; cin>>x>>y; v[y].push_back(x); } for(int i=1;i<=n;i++){ int p[v[i].size()]; memset(p,0,sizeof p); pair<int,int>num; while(pre[i].size()<sq){ for(int j=0;j<v[i].size();j++){ int x=v[i][j]; if(p[j]>=pre[x].size() )continue; while( p[j]<pre[x].size()&&mark[pre[x][p[j]].fr] )p[j]++;//cout<<j<<" "<<p[j]<<endl; if(p[j]>=pre[x].size())continue; if(pre[x][p[j]].sc+1>=num.sc){ num.sc=pre[x][p[j]].sc+1; num.fr=pre[x][p[j]].fr; } } if(num.fr==0)break; mark[num.fr]=1; pre[i].push_back(num); num={0,0}; } if(pre[i].size()<sq){ pre[i].push_back({i,0}); mark[i]=1; } for(auto j:pre[i]){ mark[j.fr]=0; } for(int j=2;j<pre[i].size();j++){ assert(pre[i][j].sc<=pre[i][j-1].sc); } } while(q--){ int t,y; cin>>t>>y; int a[y]; for(int i=0;i<y;i++){ cin>>a[i]; mark[a[i]]=1; } if(y>=sq){ int dp[t+1]; for(int i=1;i<=t;i++){ dp[i]=(mark[i])?-1e6:0; for(auto j:v[i]){ dp[i]=max(dp[i],dp[j]+1); } } if(dp[t]<0)dp[t]=-1; cout<<dp[t]<<'\n'; } else{ int d=0; for(auto i:pre[t]){ if(!mark[i.fr]){ d=1; cout<<i.sc<<'\n'; break; } } if(!d) cout<<-1<<'\n'; } for(int i=0;i<y;i++) mark[a[i]]=0; } }

Compilation message (stderr)

bitaro.cpp: In function 'int main()':
bitaro.cpp:24:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |    for(int j=0;j<v[i].size();j++){
      |                ~^~~~~~~~~~~~
bitaro.cpp:26:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     if(p[j]>=pre[x].size() )continue;
      |        ~~~~^~~~~~~~~~~~~~~
bitaro.cpp:27:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     while( p[j]<pre[x].size()&&mark[pre[x][p[j]].fr] )p[j]++;//cout<<j<<" "<<p[j]<<endl;
      |            ~~~~^~~~~~~~~~~~~~
bitaro.cpp:28:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     if(p[j]>=pre[x].size())continue;
      |        ~~~~^~~~~~~~~~~~~~~
bitaro.cpp:46:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |   for(int j=2;j<pre[i].size();j++){
      |               ~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...