Submission #1084597

# Submission time Handle Problem Language Result Execution time Memory
1084597 2024-09-06T13:02:40 Z DucNguyen2007 Bitaro’s Party (JOI18_bitaro) C++14
100 / 100
666 ms 267348 KB
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
vector<int>g[110000];
vector<int>rev[110000];
int at[110000][320];
int dist[110000][320];
const int SQ=320;
int tmp_a[330];
int tmp_b[330];
int use[110000];
int z[110000];
int dp[110000];
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<b;i++){
		int p,q;scanf("%d%d",&p,&q);p--;q--;
		g[p].push_back(q);
		rev[q].push_back(p);
	}
	for(int i=0;i<a;i++)for(int j=0;j<320;j++)
		dist[i][j]=-mod;
	for(int i=0;i<a;i++){
		dist[i][0]=0;
		at[i][0]=i;
	}
	for(int i=0;i<a;i++){
		for(int j=0;j<g[i].size();j++){
			int to=g[i][j];
			int left=0;
			int right=0;
			int sz=0;
			while(left<SQ||right<SQ){
				if(sz==SQ)break;
				int S,T;
				if((left==SQ||dist[i][left]<0)&&(right==SQ||dist[to][right]<0))break;
				if(right==SQ||(left<SQ&&dist[i][left]+1>=dist[to][right])){
					S=at[i][left];
					T=dist[i][left]+1;
					left++;
				}else{
					S=at[to][right];
					T=dist[to][right];
					right++;
				}
				if(!use[S]){
					tmp_a[sz]=S;
					tmp_b[sz]=T;
					use[S]=1;
					sz++;
				}
			}
			for(int k=0;k<sz;k++)dist[to][k]=tmp_b[k];
			for(int k=0;k<sz;k++)at[to][k]=tmp_a[k];
			for(int k=0;k<sz;k++)use[tmp_a[k]]=0;
		}
	}

	for(int i=0;i<c;i++){
		int x,y;scanf("%d%d",&x,&y);
		x--;
		for(int j=0;j<y;j++){
			scanf("%d",z+j);
			z[j]--;
		}
		for(int j=0;j<y;j++){
			use[z[j]]=1;
		}
		if(y<SQ){
			bool ok=false;
			for(int j=0;j<SQ;j++){
				if(dist[x][j]<0)break;
				if(!use[at[x][j]]){
					ok=true;
					printf("%d\n",dist[x][j]);
					break;
				}
			}
			if(!ok)printf("-1\n");
		}else{
			for(int j=0;j<a;j++){
				dp[j]=-mod;
			}
			dp[x]=0;
			for(int j=x;j>=0;j--){
				for(int k=0;k<rev[j].size();k++){
					dp[rev[j][k]]=max(dp[rev[j][k]],dp[j]+1);
				}
			}
			int ret=-1;
			for(int j=0;j<a;j++){
				if(!use[j])ret=max(ret,dp[j]);
			}
			printf("%d\n",ret);
		}
		for(int j=0;j<y;j++){
			use[z[j]]=0;
		}
	}
}

Compilation message

bitaro.cpp: In function 'int main()':
bitaro.cpp:48:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |   for(int j=0;j<g[i].size();j++){
      |               ~^~~~~~~~~~~~
bitaro.cpp:106:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |     for(int k=0;k<rev[j].size();k++){
      |                 ~^~~~~~~~~~~~~~
bitaro.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |  scanf("%d%d%d",&a,&b,&c);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
bitaro.cpp:37:16: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |   int p,q;scanf("%d%d",&p,&q);p--;q--;
      |           ~~~~~^~~~~~~~~~~~~~
bitaro.cpp:80:16: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |   int x,y;scanf("%d%d",&x,&y);
      |           ~~~~~^~~~~~~~~~~~~~
bitaro.cpp:83:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |    scanf("%d",z+j);
      |    ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5476 KB Output is correct
2 Correct 2 ms 5468 KB Output is correct
3 Correct 2 ms 5420 KB Output is correct
4 Correct 2 ms 5468 KB Output is correct
5 Correct 4 ms 8028 KB Output is correct
6 Correct 4 ms 8028 KB Output is correct
7 Correct 4 ms 8192 KB Output is correct
8 Correct 6 ms 8028 KB Output is correct
9 Correct 7 ms 8028 KB Output is correct
10 Correct 7 ms 8028 KB Output is correct
11 Correct 6 ms 8028 KB Output is correct
12 Correct 4 ms 8028 KB Output is correct
13 Correct 7 ms 8168 KB Output is correct
14 Correct 7 ms 8024 KB Output is correct
15 Correct 5 ms 8028 KB Output is correct
16 Correct 7 ms 8028 KB Output is correct
17 Correct 7 ms 8036 KB Output is correct
18 Correct 5 ms 8028 KB Output is correct
19 Correct 6 ms 8028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5476 KB Output is correct
2 Correct 2 ms 5468 KB Output is correct
3 Correct 2 ms 5420 KB Output is correct
4 Correct 2 ms 5468 KB Output is correct
5 Correct 4 ms 8028 KB Output is correct
6 Correct 4 ms 8028 KB Output is correct
7 Correct 4 ms 8192 KB Output is correct
8 Correct 6 ms 8028 KB Output is correct
9 Correct 7 ms 8028 KB Output is correct
10 Correct 7 ms 8028 KB Output is correct
11 Correct 6 ms 8028 KB Output is correct
12 Correct 4 ms 8028 KB Output is correct
13 Correct 7 ms 8168 KB Output is correct
14 Correct 7 ms 8024 KB Output is correct
15 Correct 5 ms 8028 KB Output is correct
16 Correct 7 ms 8028 KB Output is correct
17 Correct 7 ms 8036 KB Output is correct
18 Correct 5 ms 8028 KB Output is correct
19 Correct 6 ms 8028 KB Output is correct
20 Correct 317 ms 12128 KB Output is correct
21 Correct 274 ms 12116 KB Output is correct
22 Correct 311 ms 12120 KB Output is correct
23 Correct 394 ms 12012 KB Output is correct
24 Correct 501 ms 264532 KB Output is correct
25 Correct 544 ms 264684 KB Output is correct
26 Correct 540 ms 264608 KB Output is correct
27 Correct 425 ms 266036 KB Output is correct
28 Correct 399 ms 266068 KB Output is correct
29 Correct 410 ms 266068 KB Output is correct
30 Correct 454 ms 265348 KB Output is correct
31 Correct 444 ms 265296 KB Output is correct
32 Correct 461 ms 265556 KB Output is correct
33 Correct 456 ms 265556 KB Output is correct
34 Correct 425 ms 265428 KB Output is correct
35 Correct 439 ms 265380 KB Output is correct
36 Correct 546 ms 265484 KB Output is correct
37 Correct 527 ms 265556 KB Output is correct
38 Correct 549 ms 265456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5476 KB Output is correct
2 Correct 2 ms 5468 KB Output is correct
3 Correct 2 ms 5420 KB Output is correct
4 Correct 2 ms 5468 KB Output is correct
5 Correct 4 ms 8028 KB Output is correct
6 Correct 4 ms 8028 KB Output is correct
7 Correct 4 ms 8192 KB Output is correct
8 Correct 6 ms 8028 KB Output is correct
9 Correct 7 ms 8028 KB Output is correct
10 Correct 7 ms 8028 KB Output is correct
11 Correct 6 ms 8028 KB Output is correct
12 Correct 4 ms 8028 KB Output is correct
13 Correct 7 ms 8168 KB Output is correct
14 Correct 7 ms 8024 KB Output is correct
15 Correct 5 ms 8028 KB Output is correct
16 Correct 7 ms 8028 KB Output is correct
17 Correct 7 ms 8036 KB Output is correct
18 Correct 5 ms 8028 KB Output is correct
19 Correct 6 ms 8028 KB Output is correct
20 Correct 317 ms 12128 KB Output is correct
21 Correct 274 ms 12116 KB Output is correct
22 Correct 311 ms 12120 KB Output is correct
23 Correct 394 ms 12012 KB Output is correct
24 Correct 501 ms 264532 KB Output is correct
25 Correct 544 ms 264684 KB Output is correct
26 Correct 540 ms 264608 KB Output is correct
27 Correct 425 ms 266036 KB Output is correct
28 Correct 399 ms 266068 KB Output is correct
29 Correct 410 ms 266068 KB Output is correct
30 Correct 454 ms 265348 KB Output is correct
31 Correct 444 ms 265296 KB Output is correct
32 Correct 461 ms 265556 KB Output is correct
33 Correct 456 ms 265556 KB Output is correct
34 Correct 425 ms 265428 KB Output is correct
35 Correct 439 ms 265380 KB Output is correct
36 Correct 546 ms 265484 KB Output is correct
37 Correct 527 ms 265556 KB Output is correct
38 Correct 549 ms 265456 KB Output is correct
39 Correct 560 ms 265296 KB Output is correct
40 Correct 554 ms 264572 KB Output is correct
41 Correct 531 ms 264284 KB Output is correct
42 Correct 598 ms 264868 KB Output is correct
43 Correct 540 ms 264820 KB Output is correct
44 Correct 332 ms 13396 KB Output is correct
45 Correct 330 ms 12628 KB Output is correct
46 Correct 316 ms 12568 KB Output is correct
47 Correct 331 ms 12116 KB Output is correct
48 Correct 328 ms 12164 KB Output is correct
49 Correct 448 ms 266836 KB Output is correct
50 Correct 424 ms 265552 KB Output is correct
51 Correct 295 ms 13140 KB Output is correct
52 Correct 280 ms 12372 KB Output is correct
53 Correct 574 ms 266040 KB Output is correct
54 Correct 541 ms 266068 KB Output is correct
55 Correct 509 ms 265044 KB Output is correct
56 Correct 491 ms 265040 KB Output is correct
57 Correct 343 ms 13320 KB Output is correct
58 Correct 348 ms 13136 KB Output is correct
59 Correct 319 ms 12276 KB Output is correct
60 Correct 322 ms 12288 KB Output is correct
61 Correct 492 ms 266064 KB Output is correct
62 Correct 573 ms 265560 KB Output is correct
63 Correct 550 ms 265408 KB Output is correct
64 Correct 542 ms 266064 KB Output is correct
65 Correct 666 ms 265552 KB Output is correct
66 Correct 625 ms 265408 KB Output is correct
67 Correct 455 ms 265668 KB Output is correct
68 Correct 552 ms 265044 KB Output is correct
69 Correct 610 ms 265044 KB Output is correct
70 Correct 428 ms 266184 KB Output is correct
71 Correct 541 ms 265808 KB Output is correct
72 Correct 511 ms 265652 KB Output is correct
73 Correct 439 ms 266212 KB Output is correct
74 Correct 549 ms 265532 KB Output is correct
75 Correct 525 ms 265556 KB Output is correct
76 Correct 461 ms 267348 KB Output is correct
77 Correct 417 ms 265812 KB Output is correct
78 Correct 416 ms 266320 KB Output is correct
79 Correct 293 ms 13396 KB Output is correct
80 Correct 287 ms 12572 KB Output is correct
81 Correct 284 ms 12124 KB Output is correct
82 Correct 461 ms 266436 KB Output is correct
83 Correct 468 ms 266236 KB Output is correct
84 Correct 425 ms 265064 KB Output is correct
85 Correct 456 ms 265048 KB Output is correct
86 Correct 446 ms 265552 KB Output is correct
87 Correct 450 ms 265572 KB Output is correct
88 Correct 344 ms 13372 KB Output is correct
89 Correct 341 ms 13396 KB Output is correct
90 Correct 313 ms 12372 KB Output is correct
91 Correct 334 ms 12368 KB Output is correct
92 Correct 321 ms 12188 KB Output is correct
93 Correct 317 ms 12112 KB Output is correct
94 Correct 490 ms 266324 KB Output is correct
95 Correct 454 ms 266320 KB Output is correct
96 Correct 460 ms 265300 KB Output is correct
97 Correct 422 ms 265108 KB Output is correct
98 Correct 459 ms 265556 KB Output is correct
99 Correct 425 ms 265556 KB Output is correct
100 Correct 413 ms 13432 KB Output is correct
101 Correct 401 ms 13508 KB Output is correct
102 Correct 406 ms 12624 KB Output is correct
103 Correct 403 ms 12364 KB Output is correct
104 Correct 399 ms 12176 KB Output is correct
105 Correct 391 ms 12228 KB Output is correct
106 Correct 562 ms 266580 KB Output is correct
107 Correct 557 ms 266232 KB Output is correct
108 Correct 559 ms 265300 KB Output is correct
109 Correct 498 ms 265192 KB Output is correct
110 Correct 544 ms 265812 KB Output is correct
111 Correct 514 ms 265812 KB Output is correct
112 Correct 328 ms 13396 KB Output is correct
113 Correct 347 ms 13480 KB Output is correct
114 Correct 315 ms 12368 KB Output is correct
115 Correct 320 ms 12536 KB Output is correct
116 Correct 325 ms 12172 KB Output is correct
117 Correct 317 ms 12112 KB Output is correct
118 Correct 429 ms 265552 KB Output is correct
119 Correct 545 ms 265044 KB Output is correct
120 Correct 516 ms 264924 KB Output is correct
121 Correct 435 ms 265552 KB Output is correct
122 Correct 549 ms 265012 KB Output is correct
123 Correct 518 ms 265020 KB Output is correct
124 Correct 430 ms 265552 KB Output is correct
125 Correct 625 ms 265040 KB Output is correct
126 Correct 514 ms 265120 KB Output is correct