QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#860448#2824. 找树C1942huangjiaxuWA 172ms89940kbC++141.8kb2025-01-18 13:24:542025-01-18 13:27:39

Judging History

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

  • [2025-01-18 13:27:39]
  • 评测
  • 测评结果:WA
  • 用时:172ms
  • 内存:89940kb
  • [2025-01-18 13:24:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=75,P=998244853,i2=P+1>>1;
int n,m,w,a[N][N][1<<12],b[1<<12];
char op[15];
int ksm(int x,int y){
	int res=1;
	for(;y;y>>=1,x=1ll*x*x%P)if(y&1)res=1ll*res*x%P;
	return res;
}
void add(int x,int y,int z){
	--a[x][y][z],++a[y][y][z];
}
inline int md(int x){
	return x>=P?x-P:x;
}
void FWT(int *a){
	for(int i=0;i<w;++i)
		for(int j=0;j<1<<w;j+=1<<i+1)
			for(int k=0;k<1<<i;++k){
				if(op[i]=='&')a[j|k]=md(a[j|k]+a[j|k|1<<i]);
				else if(op[i]=='|')a[j|k|1<<i]=md(a[j|k]+a[j|k|1<<i]);
				else{
					int x=a[j|k],y=a[j|k|1<<i];
					a[j|k]=md(x+y),a[j|k|1<<i]=md(x+P-y);
				}
			}
}
void IFWT(int *a){
	for(int i=0;i<w;++i)
		for(int j=0;j<1<<w;j+=1<<i+1)
			for(int k=0;k<1<<i;++k){
				if(op[i]=='&')a[j|k]=md(a[j|k]+P-a[j|k|1<<i]);
				else if(op[i]=='|')a[j|k|1<<i]=md(a[j|k]+P-a[j|k|1<<i]);
				else{
					int x=a[j|k],y=a[j|k|1<<i];
					a[j|k]=1ll*(x+y)*i2%P,a[j|k|1<<i]=1ll*(x+P-y)*i2%P;
				}
			}
}
int main(){
	scanf("%d%d",&n,&m);
	scanf("%s",op);
	w=strlen(op);
	for(int i=1,x,y,z;i<=n;++i){
		scanf("%d%d%d",&x,&y,&z);
		add(x,y,z),add(y,x,z);
	}
	for(int i=1;i<n;++i)for(int j=1;j<n;++j)FWT(a[i][j]);
	for(int v=0;v<1<<w;++v){
		b[v]=1;
		for(int i=1;i<n;++i){
			if(!a[i][i][v]){
				for(int j=i+1;j<n;++j)if(a[j][i][v]){
					for(int k=i;k<n;++k)swap(a[i][k][v],a[j][k][v]);
					b[v]=P-b[v];
					break;
				}
			}
			if(!a[i][i][v]){
				b[v]=0;
				break;
			}
			b[v]=1ll*b[v]*a[i][i][v]%P;
			int in=ksm(a[i][i][v],P-2);
			for(int j=i+1;j<n;++j){
				int d=1ll*a[j][i][v]*in%P;
				for(int k=i;k<n;++k)a[j][k][v]=(1ll*(P-d)*a[i][k][v]+a[j][k][v])%P;
			}
		}
	}
	IFWT(b);
	for(int i=(1<<w)-1;~i;--i)if(b[i]){
		printf("%d\n",i);
		return 0;
	}
	puts("-1");
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 148ms
memory: 89940kb

input:

70 100
&&&&&&&&&&&&
59 1 577
11 18 513
41 11 6
7 33 1
25 26 577
3 57 516
28 5 3
13 56 0
2 32 7
66 53 517
42 31 519
41 34 70
37 54 579
24 15 512
70 32 512
51 49 64
55 19 69
3 31 517
24 8 582
44 45 513
47 58 517
47 41 577
33 22 519
57 41 0
70 50 67
3 6 6
14 43 6
21 1 579
32 27 576
62 7 514
39 36 69
12...

output:

-1

result:

ok single line: '-1'

Test #2:

score: 0
Accepted
time: 154ms
memory: 89936kb

input:

70 100
|&&&&|&&&^&&
70 50 200
51 46 9
48 33 163
14 64 137
53 54 96
32 24 160
7 22 8
40 66 192
12 22 74
20 25 66
7 40 97
27 13 192
3 15 96
43 16 195
23 6 74
7 34 33
5 5 98
12 26 99
44 38 8
27 44 32
10 67 42
19 12 234
6 39 65
27 24 8
58 13 106
37 69 32
4 2 163
33 65 168
3 3 107
56 65 8
42 53 137
32 53...

output:

-1

result:

ok single line: '-1'

Test #3:

score: -100
Wrong Answer
time: 172ms
memory: 89808kb

input:

70 5000
^&&&&|^&^&&|
70 55 35
32 4 2338
1 45 33
69 4 2337
55 51 2338
26 46 2050
8 5 33
16 51 35
32 10 1
18 67 257
12 37 2307
34 6 2051
30 10 33
21 35 2082
4 27 34
12 4 2337
44 34 2082
11 17 2338
1 2 289
22 2 34
39 68 2304
11 48 289
44 26 2080
57 12 2306
69 15 2338
16 65 2
51 67 2048
1 5 291
64 48 28...

output:

-1

result:

wrong answer 1st lines differ - expected: '2339', found: '-1'