QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#833047#9241. Sphinxdongyc666#0 22ms3868kbC++173.8kb2024-12-26 12:27:202024-12-26 12:27:21

Judging History

你现在查看的是最新测评结果

  • [2024-12-26 12:27:21]
  • 评测
  • 测评结果:0
  • 用时:22ms
  • 内存:3868kb
  • [2024-12-26 12:27:20]
  • 提交

answer

#include "sphinx.h"
#include<bits/stdc++.h>
using namespace std;
const int NR=300;
int n,m,c[NR],fa[NR],tot,cnt,opt[NR],ans[NR];
vector<int>g[NR];
#define pb emplace_back

void init(){
	for(int i=1;i<=n;i++)fa[i]=i;
	cnt=n;
}
int get(int x){
	if(fa[x]==x)return x;
	return fa[x]=get(fa[x]);
}
void merge(int x,int y){
	x=get(x);y=get(y);
	if(x==y)return;
	fa[x]=y;cnt--;
}

vector<int> find_colours(int N, vector<int> X, vector<int> Y) {
	n=N;m=X.size(); 
	for(int i=0;i<m;i++)g[X[i]+1].pb(Y[i]+1),g[Y[i]+1].pb(X[i]+1);
	for(int i=1;i<=n;i++)c[i]=i-1;
	for(int i=1;i<=n;i++){
		vector<int>buc;
		for(int x:g[i])
			if(x<i)buc.pb(x);
		if(!buc.size())continue;
		sort(buc.begin(),buc.end());
//		printf("i:%d\n",i);
//		for(int x:buc)printf("%d ",x);puts("");
		int L=0,R=buc.size()-1;
		while(L<=R){
			init();
			for(int j=1;j<=n;j++)opt[j]=-1;
			for(int j=L;j<=R;j++)opt[buc[j]]=1;
			opt[i]=1;
			for(int j=1;j<=n;j++)
				for(int x:g[j])
					if(opt[j]==opt[x]){
						if(opt[j]==-1)merge(j,x);
						else if(c[j]==c[x])merge(j,x);
					}
//			printf("mid:%d cnt:%d\n",mid,cnt);
//			for(int j=1;j<=n;j++)printf("%d ",opt[j]);puts("");
//			for(int j=1;j<=n;j++)printf("%d ",get(j));puts("");
			vector<int>arr;
			for(int i=1;i<=n;i++)
				if(opt[i]==-1)arr.pb(n);
				else arr.pb(-1);
			int tmp=perform_experiment(arr);
			if(tmp==cnt)break;
			int l=L,r=R,res=-1;
			while(l<=r){
				int mid=(l+r)>>1;init();
				for(int j=1;j<=n;j++)opt[j]=-1;
				for(int j=L;j<=mid;j++)opt[buc[j]]=1;
				opt[i]=1;
				for(int j=1;j<=n;j++)
					for(int x:g[j])
						if(opt[j]==opt[x]){
							if(opt[j]==-1)merge(j,x);
							else if(c[j]==c[x])merge(j,x);
						}
	//			printf("mid:%d cnt:%d\n",mid,cnt);
	//			for(int j=1;j<=n;j++)printf("%d ",opt[j]);puts("");
	//			for(int j=1;j<=n;j++)printf("%d ",get(j));puts("");
				vector<int>arr;
				for(int i=1;i<=n;i++)
					if(opt[i]==-1)arr.pb(n);
					else arr.pb(-1);
				int tmp=perform_experiment(arr);
	//			printf("tmp:%d\n",tmp);
				if(tmp!=cnt)res=mid,r=mid-1;
				else l=mid+1; 
			}
			if(res==-1)break;
			else{
				int x=c[buc[res]];
				for(int j=1;j<=n;j++)
					if(c[j]==x)c[j]=i-1;
				L=res+1;
			}
		}
	}
	for(int i=1;i<=n;i++)
		if(c[i]==i-1){
			vector<int>buc;
			for(int j=1;j<=n;j++)
				if(c[i]==c[j])buc.pb(j);
			set<int>s;
			for(int x:buc)
				for(int y:g[x])
					if(c[y]!=c[i])s.insert(y);
			int k=s.size(),now=0,res=-1,l,r;
//			printf("i:%d\n",i);
			while(now<n-1){
				for(int j=1;j<=n;j++)opt[j]=-1;
				for(int x:buc)opt[x]=1;
				for(int x:s)opt[x]=0;
				init();
				for(int j=1;j<=n;j++)
					for(int x:g[j])
						if(opt[j]==opt[x]&&opt[j]){
							if(opt[j]==-1)merge(j,x);
							else if(c[j]==c[x])merge(j,x);
						}
				vector<int>arr;
				for(int i=1;i<=n;i++)
					if(!opt[i])arr.pb(now++);
					else if(opt[i]==-1)arr.pb(n);
					else arr.pb(-1);
//				for(int i=0;i<n;i++)cout<<arr[i]<<' ';cout<<endl;
				int tmp=perform_experiment(arr);
//				printf("now:%d k:%d %d %d\n",now,k,cnt,tmp);
				if(tmp!=cnt){
					r=min(now-1,n-2);l=now-k;res=0;
					break;
				}
			}
			if(res==-1)ans[i]=n-1;
			else{
				while(l<r){
					int mid=(l+r)>>1;
					for(int j=1;j<=n;j++)opt[j]=-1;
					for(int x:buc)opt[x]=1;
					for(int x:s)opt[x]=0;
					init();
					for(int j=1;j<=n;j++)
						for(int x:g[j])
							if(opt[j]==opt[x]&&opt[j]){
								if(opt[j]==-1)merge(j,x);
								else if(c[j]==c[x])merge(j,x);
							}
					vector<int>arr;
					int now=l;
					for(int i=1;i<=n;i++)
						if(!opt[i])arr.pb(min(now++,mid));
						else if(opt[i]==-1)arr.pb(n);
						else arr.pb(-1);
					int tmp=perform_experiment(arr);
					if(tmp!=cnt)r=mid;
					else l=mid+1;
				}
				ans[i]=l;
			}
		}
	vector<int>arr;
	for(int i=1;i<=n;i++)arr.pb(ans[c[i]+1]);
	return arr;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

1978433568
2
1
0
1
1978433568
1
1978433568
1
1978433568
1
1978433568
1
1978433568
1
1978433568
1
1978433568
1
1978433568
1
1978433568
1
1978433568
1
1978433568
1
1978433568
1
1978433568
1
1978433568
1
1978433568
1
1978433568
1
1978433568
1
1978433568
1
1978433568
1
1978433568
1
1978433568
1
19784335...

output:

877694080
-1
-1
877694080
-1
-1
877694080
-1
-1
877694080
-1
-1
877694080
-1
-1
877694080
-1
-1
877694080
-1
-1
877694080
-1
-1
877694080
-1
-1
877694080
-1
-1
877694080
-1
-1
877694080
-1
-1
877694080
-1
-1
877694080
-1
-1
877694080
-1
-1
877694080
-1
-1
877694080
-1
-1
877694080
-1
-1
877694080
-1...

result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Runtime Error

Test #34:

score: 33
Accepted
time: 14ms
memory: 3836kb

input:

1978433568
250
249
0
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
11
11
12
12
13
13
14
14
15
15
16
16
17
17
18
18
19
19
20
20
21
21
22
22
23
23
24
24
25
25
26
26
27
27
28
28
29
29
30
30
31
31
32
32
33
33
34
34
35
35
36
36
37
37
38
38
39
39
40
40
41
41
42
42
43
43
44
44
45
45
46
46
47
47
48
48
49
49
50
...

output:

877694080
-1
-1
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
...

result:

ok #experiments: 616

Test #35:

score: 33
Accepted
time: 21ms
memory: 3780kb

input:

1978433568
250
249
0
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
11
11
12
12
13
13
14
14
15
15
16
16
17
17
18
18
19
19
20
20
21
21
22
22
23
23
24
24
25
25
26
26
27
27
28
28
29
29
30
30
31
31
32
32
33
33
34
34
35
35
36
36
37
37
38
38
39
39
40
40
41
41
42
42
43
43
44
44
45
45
46
46
47
47
48
48
49
49
50
...

output:

877694080
-1
-1
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
...

result:

ok #experiments: 1056

Test #36:

score: 33
Accepted
time: 16ms
memory: 3768kb

input:

1978433568
250
249
0
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
11
11
12
12
13
13
14
14
15
15
16
16
17
17
18
18
19
19
20
20
21
21
22
22
23
23
24
24
25
25
26
26
27
27
28
28
29
29
30
30
31
31
32
32
33
33
34
34
35
35
36
36
37
37
38
38
39
39
40
40
41
41
42
42
43
43
44
44
45
45
46
46
47
47
48
48
49
49
50
...

output:

877694080
-1
-1
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
...

result:

ok #experiments: 1273

Test #37:

score: 33
Accepted
time: 22ms
memory: 3868kb

input:

1978433568
250
249
0
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
11
11
12
12
13
13
14
14
15
15
16
16
17
17
18
18
19
19
20
20
21
21
22
22
23
23
24
24
25
25
26
26
27
27
28
28
29
29
30
30
31
31
32
32
33
33
34
34
35
35
36
36
37
37
38
38
39
39
40
40
41
41
42
42
43
43
44
44
45
45
46
46
47
47
48
48
49
49
50
...

output:

877694080
-1
-1
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
...

result:

ok #experiments: 1508

Test #38:

score: 0
Runtime Error

input:

1978433568
250
249
0
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
11
11
12
12
13
13
14
14
15
15
16
16
17
17
18
18
19
19
20
20
21
21
22
22
23
23
24
24
25
25
26
26
27
27
28
28
29
29
30
30
31
31
32
32
33
33
34
34
35
35
36
36
37
37
38
38
39
39
40
40
41
41
42
42
43
43
44
44
45
45
46
46
47
47
48
48
49
49
50
...

output:

877694080
-1
-1
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
...

result:


Subtask #4:

score: 0
Runtime Error

Test #43:

score: 0
Runtime Error

input:

1978433568
250
31125
0
1
0
2
0
3
0
4
0
5
0
6
0
7
0
8
0
9
0
10
0
11
0
12
0
13
0
14
0
15
0
16
0
17
0
18
0
19
0
20
0
21
0
22
0
23
0
24
0
25
0
26
0
27
0
28
0
29
0
30
0
31
0
32
0
33
0
34
0
35
0
36
0
37
0
38
0
39
0
40
0
41
0
42
0
43
0
44
0
45
0
46
0
47
0
48
0
49
0
50
0
51
0
52
0
53
0
54
0
55
0
56
0
57
0
5...

output:

877694080
-1
-1
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
...

result:


Subtask #5:

score: 0
Skipped

Dependency #1:

0%