Submission #69640

# Submission time Handle Problem Language Result Execution time Memory
69640 2018-08-21T10:28:16 Z yogahmad Bitaro’s Party (JOI18_bitaro) C++14
14 / 100
2000 ms 427296 KB
#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 fbo find_by_order
#define ook order_of_key
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define MOD 1000000007
#define MID (l+r)/2
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mx 100003
#define pc(x) putchar_unlocked(x);
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int batas=330;
int n,m,q,u,v,t[mx],y[mx],di[mx],dp[mx],ans[mx];
vector<int>ve[mx],isi[mx],b[mx],g[mx];
vector<pair<int,int>>jauh[mx];
bool sudah[mx],ya[mx];
int sem=0;


int main(){
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&u,&v);
		g[u].pb(v);
		b[v].pb(u);
	}
	for(int i=1;i<=q;i++){
		cin>>t[i]>>y[i];
		for(int j=1;j<=y[i];j++){
			int x;
			cin>>x;
			ve[i].pb(x);
		}
		isi[t[i]].pb(i);
	}
	reset(dp,-1);
	for(int i=1;i<=n;i++){
		for(int j:b[i]){
			di[j]=0;
		}
		while(jauh[i].size()<batas+10){
			int ambil=-1,brp=-1;
			for(int j:b[i]){
				while(di[j]<jauh[j].size() && sudah[jauh[j][di[j]].s])di[j]++;
				if(di[j]==jauh[j].size())continue;
				if(brp<jauh[j][di[j]].f){
					brp=jauh[j][di[j]].f;
					ambil=j;
				}
			}
			if(ambil==-1)break;
			int j=ambil;
			jauh[i].pb({brp+1,jauh[j][di[j]].s});
			sudah[jauh[j][di[j]].s]=true;
			di[j]++;
		}
		jauh[i].pb({0,i});
		for(auto x:jauh[i]){
			sudah[x.s]=false;
		}
		for(int x:isi[i]){
			if(y[x]>=batas){
				for(int j:ve[x])ya[j]=true;
				dp[i]=0;
				for(int j=i-1;j>=1;j--){
					for(int k:g[j]){
						if(dp[k]!=-1)dp[j]=max(dp[j],dp[k]+1);
					}
				}
				int aa=-1;
				for(int j=1;j<=i;j++){
					if(!ya[j])aa=max(aa,dp[j]);
				}
				ans[x]=aa;
				for(int j=1;j<=i;j++){
					dp[j]=-1;
				}
				for(int j:ve[x])ya[j]=false;
			}
			else{
				//debug(x);
				for(int j:ve[x])ya[j]=true;
				int aa=-1;
				for(auto j:jauh[i]){
					if(i==2){
					//	cout<<"INI "<<j.f<<" "<<j.s<<endl;
					}
					if(!ya[j.s]){
						aa=j.f;
						break;
					}
				}
				ans[x]=aa;
				for(int j:ve[x])ya[j]=false;
			}
		}
	}
	for(int i=1;i<=q;i++)printf("%d\n",ans[i]);
}



Compilation message

bitaro.cpp: In function 'int main()':
bitaro.cpp:52:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(di[j]<jauh[j].size() && sudah[jauh[j][di[j]].s])di[j]++;
           ~~~~~^~~~~~~~~~~~~~~
bitaro.cpp:53:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(di[j]==jauh[j].size())continue;
        ~~~~~^~~~~~~~~~~~~~~~
bitaro.cpp:29:7: 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:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&u,&v);
   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 12408 KB Output is correct
2 Correct 14 ms 12664 KB Output is correct
3 Correct 14 ms 12664 KB Output is correct
4 Correct 14 ms 12664 KB Output is correct
5 Correct 19 ms 13136 KB Output is correct
6 Correct 19 ms 13136 KB Output is correct
7 Correct 19 ms 13184 KB Output is correct
8 Correct 24 ms 16164 KB Output is correct
9 Correct 24 ms 16164 KB Output is correct
10 Correct 23 ms 16164 KB Output is correct
11 Correct 25 ms 16164 KB Output is correct
12 Correct 21 ms 16164 KB Output is correct
13 Correct 24 ms 16164 KB Output is correct
14 Correct 24 ms 16164 KB Output is correct
15 Correct 20 ms 16164 KB Output is correct
16 Correct 23 ms 16164 KB Output is correct
17 Correct 24 ms 16164 KB Output is correct
18 Correct 22 ms 16164 KB Output is correct
19 Correct 24 ms 16164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 12408 KB Output is correct
2 Correct 14 ms 12664 KB Output is correct
3 Correct 14 ms 12664 KB Output is correct
4 Correct 14 ms 12664 KB Output is correct
5 Correct 19 ms 13136 KB Output is correct
6 Correct 19 ms 13136 KB Output is correct
7 Correct 19 ms 13184 KB Output is correct
8 Correct 24 ms 16164 KB Output is correct
9 Correct 24 ms 16164 KB Output is correct
10 Correct 23 ms 16164 KB Output is correct
11 Correct 25 ms 16164 KB Output is correct
12 Correct 21 ms 16164 KB Output is correct
13 Correct 24 ms 16164 KB Output is correct
14 Correct 24 ms 16164 KB Output is correct
15 Correct 20 ms 16164 KB Output is correct
16 Correct 23 ms 16164 KB Output is correct
17 Correct 24 ms 16164 KB Output is correct
18 Correct 22 ms 16164 KB Output is correct
19 Correct 24 ms 16164 KB Output is correct
20 Correct 513 ms 18392 KB Output is correct
21 Correct 477 ms 18540 KB Output is correct
22 Correct 498 ms 18548 KB Output is correct
23 Correct 630 ms 18548 KB Output is correct
24 Correct 1360 ms 261656 KB Output is correct
25 Correct 1343 ms 273320 KB Output is correct
26 Correct 1255 ms 273320 KB Output is correct
27 Correct 1450 ms 421920 KB Output is correct
28 Correct 1401 ms 421920 KB Output is correct
29 Correct 1336 ms 421920 KB Output is correct
30 Correct 1441 ms 421920 KB Output is correct
31 Correct 1473 ms 421920 KB Output is correct
32 Correct 1517 ms 421920 KB Output is correct
33 Correct 1113 ms 421920 KB Output is correct
34 Correct 933 ms 421920 KB Output is correct
35 Correct 1020 ms 421920 KB Output is correct
36 Correct 1244 ms 421920 KB Output is correct
37 Correct 1159 ms 421920 KB Output is correct
38 Correct 1321 ms 421920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 12408 KB Output is correct
2 Correct 14 ms 12664 KB Output is correct
3 Correct 14 ms 12664 KB Output is correct
4 Correct 14 ms 12664 KB Output is correct
5 Correct 19 ms 13136 KB Output is correct
6 Correct 19 ms 13136 KB Output is correct
7 Correct 19 ms 13184 KB Output is correct
8 Correct 24 ms 16164 KB Output is correct
9 Correct 24 ms 16164 KB Output is correct
10 Correct 23 ms 16164 KB Output is correct
11 Correct 25 ms 16164 KB Output is correct
12 Correct 21 ms 16164 KB Output is correct
13 Correct 24 ms 16164 KB Output is correct
14 Correct 24 ms 16164 KB Output is correct
15 Correct 20 ms 16164 KB Output is correct
16 Correct 23 ms 16164 KB Output is correct
17 Correct 24 ms 16164 KB Output is correct
18 Correct 22 ms 16164 KB Output is correct
19 Correct 24 ms 16164 KB Output is correct
20 Correct 513 ms 18392 KB Output is correct
21 Correct 477 ms 18540 KB Output is correct
22 Correct 498 ms 18548 KB Output is correct
23 Correct 630 ms 18548 KB Output is correct
24 Correct 1360 ms 261656 KB Output is correct
25 Correct 1343 ms 273320 KB Output is correct
26 Correct 1255 ms 273320 KB Output is correct
27 Correct 1450 ms 421920 KB Output is correct
28 Correct 1401 ms 421920 KB Output is correct
29 Correct 1336 ms 421920 KB Output is correct
30 Correct 1441 ms 421920 KB Output is correct
31 Correct 1473 ms 421920 KB Output is correct
32 Correct 1517 ms 421920 KB Output is correct
33 Correct 1113 ms 421920 KB Output is correct
34 Correct 933 ms 421920 KB Output is correct
35 Correct 1020 ms 421920 KB Output is correct
36 Correct 1244 ms 421920 KB Output is correct
37 Correct 1159 ms 421920 KB Output is correct
38 Correct 1321 ms 421920 KB Output is correct
39 Correct 1561 ms 421920 KB Output is correct
40 Correct 1264 ms 421920 KB Output is correct
41 Correct 1303 ms 421920 KB Output is correct
42 Correct 1382 ms 421920 KB Output is correct
43 Correct 1195 ms 421920 KB Output is correct
44 Correct 653 ms 421920 KB Output is correct
45 Correct 557 ms 421920 KB Output is correct
46 Correct 539 ms 421920 KB Output is correct
47 Correct 601 ms 421920 KB Output is correct
48 Correct 541 ms 421920 KB Output is correct
49 Correct 1722 ms 427296 KB Output is correct
50 Correct 1456 ms 427296 KB Output is correct
51 Correct 542 ms 427296 KB Output is correct
52 Correct 473 ms 427296 KB Output is correct
53 Correct 1515 ms 427296 KB Output is correct
54 Correct 1495 ms 427296 KB Output is correct
55 Correct 1337 ms 427296 KB Output is correct
56 Correct 1230 ms 427296 KB Output is correct
57 Correct 640 ms 427296 KB Output is correct
58 Correct 680 ms 427296 KB Output is correct
59 Correct 524 ms 427296 KB Output is correct
60 Correct 541 ms 427296 KB Output is correct
61 Correct 1631 ms 427296 KB Output is correct
62 Correct 1393 ms 427296 KB Output is correct
63 Correct 1414 ms 427296 KB Output is correct
64 Execution timed out 2055 ms 427296 KB Time limit exceeded
65 Halted 0 ms 0 KB -