QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#420427#2824. 找树300_205_205#WA 255ms163072kbC++203.1kb2024-05-24 18:04:482024-05-24 18:04:57

Judging History

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

  • [2024-05-24 18:04:57]
  • 评测
  • 测评结果:WA
  • 用时:255ms
  • 内存:163072kb
  • [2024-05-24 18:04:48]
  • 提交

answer

//#pragma GCC optimize(2)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define N 200005
#define mod 998244353
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define ls (rt<<1)
#define rs ((rt<<1)|1)
#define fi first
#define se second
#define INF 1e9
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
int qpow(int a,int b){
	int res=1;
	for(;b;b>>=1){
		if(b&1) res=res*a%mod;
		a=a*a%mod;
	}
	return res;
}
/*int fac[N],ifac[N];
int C(int n,int m){
	if(m>n||m<0||n<0) return 0;
	return fac[n]*ifac[n-m]%mod*ifac[m]%mod;
}
void init(){
	fac[0]=1;
	for(int i=1;i<N;i++) fac[i]=fac[i-1]*i%mod;
	ifac[N-1]=qpow(fac[N-1],mod-2);
	for(int i=N-2;i>=0;i--) ifac[i]=ifac[i+1]*(i+1)%mod;
}*/
inline int lowbit(int x){return x&(-x);}
inline int read(){
	int x=0,t=1;char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') t=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch-'0');
		ch=getchar();
	}
	return x*t;
}
inline void write(int x){
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10+'0');
}
#define djq 998244353
int T,n,m,w,b[71][71],res[1<<12];
int op[12],v[71][71][1<<12];
const int inv2=(djq+1)/2;
inline int add(const int a,const int b){ return a+b>=djq?a+b-djq:a+b; }
inline int inc(const int a,const int b){ return a<b?a-b+djq:a-b; }
void FWT(int* a,int n,int opt){
	for(int i=1,lw=0;i<n;i<<=1,++lw){
		const int len=(i<<1);
		for(int j=0;j<n;j+=len){
			for(int k=0;k<i;++k){
				const int x=a[j+k],y=a[j+k+i];
				if(op[lw]==0){
					if(opt) a[j+k]=add(x,y);
					else a[j+k]=inc(x,y);
				}else if(op[lw]==1){
					if(opt) a[j+k+i]=add(x,y);
					else a[j+k+i]=inc(y,x);
				}else{
					a[j+k]=add(x,y),a[j+k+i]=inc(x,y);
					if(!opt) a[j+k]=1ll*a[j+k]*inv2%djq,a[j+k+i]=1ll*a[j+k+i]*inv2%djq;
				}
			}
		}
	}
}
int det(){
	int ans=1;
	for(int i=1;i<n;i++){
		int pos=0;
		for(int j=i;j<n;j++)
			if(b[j][i]){
				pos=j;
				break;
			}
		if(!pos){
			cout<<i<<"X"<<endl;
			return 0;
		}
		if(i!=pos){
			for(int j=i;j<n;j++) swap(b[i][j],b[pos][j]);
			ans=mod-ans;
		}
		ans=ans*b[i][i]%mod;int tmp=qpow(b[i][i],mod-2);
		for(int j=i;j<n;j++) b[i][j]=b[i][j]*tmp%mod;
		for(int j=i+1;j<n;j++){
			int tmp=b[j][i];
			for(int k=i;k<=n;k++) b[j][k]=(b[j][k]-tmp*b[i][k]%mod+mod)%mod;
		}
	}
	for(int i=1;i<n;i++) ans=ans*b[i][i]%mod;
	return ans;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n>>m;string s;cin>>s;w=s.size();
	for(int i=0;i<w;i++){
		if(s[i]=='&') op[i]=0;
		else if(s[i]=='|') op[i]=1;
		else op[i]=2;
	}
	for(int i=1;i<=m;i++){
		int x,y,u;cin>>x>>y>>u;
		(v[x][y][u]+=mod-1)%=mod;
		(v[y][x][u]+=mod-1)%=mod;
		v[x][x][u]++;v[y][y][u]++;
	}
	for(int j=1;j<=n;j++)
		for(int k=1;k<=n;k++)
			FWT(v[j][k],(1<<w),1);
	for(int i=0;i<(1<<w);i++){
		for(int j=1;j<=n;j++)
			for(int k=1;k<=n;k++)
				b[j][k]=v[j][k][i];
		res[i]=det();
	}
	FWT(res,(1<<w),0);
	int ans=-1;
	for(int i=0;i<(1<<w);i++)
		if(res[i]) ans=i;
	cout<<ans<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 255ms
memory: 163072kb

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:

48X
9X
4X
3X
5X
1X
4X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
2X
2X
2X
2X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X
1X...

result:

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