QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#554440#9241. Sphinxlgvc21 230ms5084kbC++234.8kb2024-09-09 11:16:582024-09-09 11:16:58

Judging History

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

  • [2024-09-09 11:16:58]
  • 评测
  • 测评结果:21
  • 用时:230ms
  • 内存:5084kb
  • [2024-09-09 11:16:58]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#include "sphinx.h"
int n,m;
vector<int>C,G;
int fa[255],u[100005],v[100005];
int findfather(int x){
	return x==fa[x]?x:fa[x]=findfather(fa[x]);
}
int aa[255];
int findaa(int x){
	return x==aa[x]?x:aa[x]=findaa(aa[x]);
}
bool fff=0;int ct=0;
int qqq(std::vector<int> x) {
	ct++;
	assert(ct<=2500);
	int tx=perform_experiment(x);
	return tx;
}
vector<int>gg[255];
int ss[255],vist[255],tt,I;
int query(int l,int r){
	for(int i=0;i<n;++i)vist[i]=0,aa[i]=i,C[i]=n;
	for(int i=l;i<=r;++i)for(auto cu:gg[ss[i]])vist[cu]=1,C[cu]=-1;
	vist[I]=1,C[I]=-1;
	for(int i=0;i<m;++i)if(!vist[u[i]]&&!vist[v[i]]){
		int fu=findaa(u[i]),fv=findaa(v[i]);
		if(fu!=fv)aa[fu]=fv;
	}
	int cnt=0;
	for(int i=0;i<n;++i)if(!vist[i]&&aa[i]==i)++cnt;
	return r-l+1+1+cnt-qqq(C);
}
double ef=0.382;
long double f[1009];
int f2[1009];
void solve(int l,int r,int k){
	if(!k)return;
	if(l==r){
		fa[ss[l]]=I;
		return;
	}
	int mid=l+f2[r-l+1]-1;
	int k1=query(l,mid);
	solve(l,mid,k1);
	solve(mid+1,r,k-k1);
}
int s1[255],s2[255];
vector<int>g[255];
int dep[255];
void dfs(int x){
	vist[x]=1;
	for(auto cu:g[x])if(!vist[cu]){
		dep[cu]=dep[x]+1;
		dfs(cu);
	}
}
int p[255],v1[255],v2[255],ss1[255],ss2[255];
int query1(int l,int r,int d){
	if(l>r) return 0;
	for(int i=0;i<n;++i)vist[i]=0,aa[i]=i,C[i]=d;
	for(int i=l;i<=r;++i)for(auto cu:gg[ss1[i]])vist[cu]=1,C[cu]=-1;
	for(int i=0;i<m;++i)if(!vist[u[i]]&&!vist[v[i]]){
		int fu=findaa(u[i]),fv=findaa(v[i]);
		if(fu!=fv)aa[fu]=fv;
	}
	int cnt=0;
	for(int i=0;i<n;++i)if(!vist[i]&&aa[i]==i)++cnt;
	if(cnt==1||fff) return r-l+1+cnt-qqq(C);
	else if(r-l+1+cnt-qqq(C)) return -1;
	else return 0;
}
int query2(int l,int r,int d){
	if(l>r) return 0;
	for(int i=0;i<n;++i)vist[i]=0,aa[i]=i,C[i]=d;
	for(int i=l;i<=r;++i)for(auto cu:gg[ss2[i]])vist[cu]=1,C[cu]=-1;
	for(int i=0;i<m;++i)if(!vist[u[i]]&&!vist[v[i]]){
		int fu=findaa(u[i]),fv=findaa(v[i]);
		if(fu!=fv)aa[fu]=fv;
	}
	int cnt=0;
	for(int i=0;i<n;++i)if(!vist[i]&&aa[i]==i)++cnt;
	if(cnt==1||fff) return r-l+1+cnt-qqq(C);
	else if(r-l+1+cnt-qqq(C)) return -1;
	else return 0;
}
void solve1(int l,int r,int d,int k){
	if(k==0) return;
	if(l==r){
		G[ss1[l]]=d;v1[ss1[l]]=1;
		return;
	}
	int mid=l+f2[r-l+1]-1;
	int f1=query1(l,mid,d);
	if(0==f1){
		if(k!=-1&&f1!=-1) k-=f1;else k=-1; 
		solve1(mid+1,r,d,k);
	}else{
		solve1(l,mid,d,f1);
		if(k!=-1&&f1!=-1) k-=f1;else k=query1(mid+1,r,d); 
		solve1(mid+1,r,d,k);
	}
}
void solve2(int l,int r,int d,int k){
	if(k==0) return;
	if(l==r){
		G[ss2[l]]=d;v2[ss2[l]]=1;
		return;
	}
	int mid=l+f2[r-l+1]-1;
	int f1=query2(l,mid,d);
	if(0==f1){
		if(k!=-1&&f1!=-1) k-=f1;else k=-1; 
		solve2(mid+1,r,d,k);
	}else{
		solve2(l,mid,d,f1);
		if(k!=-1&&f1!=-1) k-=f1;else k=query2(mid+1,r,d); 
		solve2(mid+1,r,d,k);
	}
}
vector<int>find_colours(int N,vector<int>X,vector<int>Y){
	for(int i=2;i<=250;i++) {
		f[i]=114514;
		for(int j=1;j<i;j++) {
			if(f[i]>(f[j]*j+f[i-j]*(i-j)+(i+j))/i) {
				f[i]=(f[j]*j+f[i-j]*(i-j)+(i+j))/i;
				f2[i]=j;
			}
		}
	//	printf("%.12Lf %d\n",f[i],f2[i]);
	}
	long double as=1;
	for(int i=1;i<=125;i++) as+=f[i]+1;
	//printf("%.12Lf\n",as*2);
	n=N;m=X.size();
	C.resize(n);G.resize(n);
	for(int i=0;i<m;++i){
		u[i]=X[i],v[i]=Y[i];
	}
	for(int i=0;i<n;++i)fa[i]=i;
	for(int i=0;i<n;++i)p[i]=i;
	mt19937 mt(time(0));
	if(m>n-1) {
		shuffle(p,p+n,mt);
		for(int x=1;x<n;++x){
			int i=p[x];
			I=i;
			for(int j=0;j<x;++j)gg[p[j]].clear();
			for(int j=0;j<x;++j){
				gg[findfather(p[j])].emplace_back(p[j]);
			}
			tt=0;
			for(int j=0;j<x;++j)if(gg[p[j]].size())ss[++tt]=p[j];
			solve(1,tt,query(1,tt));
		}
	} else fff=1;
	for(int j=0;j<n;++j)gg[j].clear();
	for(int j=0;j<n;++j){
		gg[findfather(j)].emplace_back(j);
	}
	for(int i=0;i<n;++i)g[i].clear();
	for(int i=0;i<m;++i)if(findfather(u[i])!=findfather(v[i])){
		int fu=fa[u[i]],fv=fa[v[i]];
		g[fu].emplace_back(fv);
		g[fv].emplace_back(fu);
	}
	int r=findfather(0);
	for(int i=0;i<n;++i)vist[i]=0;
	dep[r]=0;dfs(r);
	int t1=0,t2=0;
	for(int i=0;i<n;++i)if(fa[i]==i){
		if(dep[i]%2)s1[++t1]=i;
		else s2[++t2]=i;
	}
	if(t1+t2==1){
		for(int i=0;i<n;++i){
			for(int j=0;j<n;++j)G[j]=(j==0?-1:i);
			if(qqq(G)==1){
				for(int j=0;j<n;++j)G[j]=i;
				break;
			}
		}
		return G;
	}
	for(int i=0;i<n;++i)v1[i]=v2[i]=0;
	for(int i=0;i<n;++i)p[i]=i;
	shuffle(p,p+n,mt);
	for(int dd=0;dd<n;++dd){
		int d=p[dd];
		int tt1=0,tt2=0;
		for(int i=1;i<=t1;++i)if(!v1[s1[i]]){
			ss1[++tt1]=s1[i];
		}
		for(int i=1;i<=t2;++i)if(!v2[s2[i]]){
			ss2[++tt2]=s2[i];
		}
		shuffle(ss1+1,ss1+tt1+1,mt);
		shuffle(ss2+1,ss2+tt2+1,mt);
		if(tt1)solve1(1,tt1,d,query1(1,tt1,d));
		if(tt2)solve2(1,tt2,d,query2(1,tt2,d));
	}
	if(fff) for(int i=0;i<n;i++) G[i]=fa[i];
	else for(int i=0;i<n;++i)G[i]=G[fa[i]];
	return G;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3884kb

input:

1978433568
2
1
0
1
1978433568
1
1978433568
1

output:

877694080
0
-1
877694080
-1
0
877694081
0
1

result:

wrong answer Vertices 0 and 1 do have the same color, but they do not in returned answer

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #34:

score: 0
Wrong Answer
time: 11ms
memory: 4016kb

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
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51
-1
51...

result:

wrong answer Vertices 0 and 1 do have the same color, but they do not in returned answer

Subtask #4:

score: 21
Accepted

Test #43:

score: 21
Accepted
time: 64ms
memory: 4840kb

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
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
-1
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250...

result:

ok #experiments: 785

Test #44:

score: 21
Accepted
time: 118ms
memory: 4828kb

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
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
-1
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250...

result:

ok #experiments: 1336

Test #45:

score: 21
Accepted
time: 168ms
memory: 5084kb

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
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
25...

result:

ok #experiments: 1753

Test #46:

score: 21
Accepted
time: 180ms
memory: 4812kb

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
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
25...

result:

ok #experiments: 1921

Test #47:

score: 21
Accepted
time: 230ms
memory: 4852kb

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
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
25...

result:

ok #experiments: 2163

Test #48:

score: 21
Accepted
time: 221ms
memory: 4980kb

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
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
25...

result:

ok #experiments: 2225

Test #49:

score: 21
Accepted
time: 205ms
memory: 4960kb

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
250
250
250
250
250
250
250
250
250
250
-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
-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
...

result:

ok #experiments: 2214

Test #50:

score: 21
Accepted
time: 15ms
memory: 4872kb

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
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
25...

result:

ok #experiments: 309

Test #51:

score: 21
Accepted
time: 222ms
memory: 4872kb

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
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
250
25...

result:

ok #experiments: 2225

Subtask #5:

score: 0
Skipped

Dependency #1:

0%