QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#237746#7687. Randias Permutation Taskucup-team958#RE 0ms0kbC++141.7kb2023-11-04 14:52:302023-11-04 14:52:31

Judging History

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

  • [2023-11-04 14:52:31]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-11-04 14:52:30]
  • 提交

answer

#include<bits/stdc++.h>
#define il inline
using namespace std;
const int maxn=185;
const int mod=1e9+7;
const int P=1e7+7;
const int maxs=400010;
il int read(){
	int x=0;
	char c=getchar();
	for(;!(c>='0'&&c<='9');c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
		x=(x<<1)+(x<<3)+c-'0';
	return x;
}
int n,m;
struct pre{
	int p[10];
	int val(int sum=0){
		for(int i=1;i<=n;i++)
			sum=(1ll*sum*n+p[i]-1)%mod;
		return sum%P;
	}
	bool operator ==(pre a)const{
		for(int i=1;i<=n;i++)
			if(p[i]!=a.p[i]) return 0;
		return 1;
	}
}A[maxn];
struct node{
	pre v;
	int k,to;
}e[2][maxs];
int head[2][P],ecnt[2];
int Find(int t,pre &x,int k){
	int v=x.val();
	for(int i=head[t][v];i;i=e[t][i].to)
		if(e[t][i].v==x&&e[t][i].k==k) return i;
	e[t][++ecnt[t]].v=x,e[t][ecnt[t]].k=k;
	e[t][ecnt[t]].to=head[t][v],head[t][v]=ecnt[t];
}
int main(){
	n=read(),m=read();
	for(int i=1;i<=m;i++)
		for(int j=1;j<=n;j++)
			A[i].p[j]=read();
	pre t1,t2;
	int k;
	if(m<=19){
		int state=1<<m;
		for(int s=1;s<state;s++){
			for(int i=1;i<=n;i++) t1.p[i]=i;
			for(int i=1;i<=n;i++)
				if(s&(1<<i-1)){
					for(int j=1;j<=n;j++) t2.p[j]=t1.p[A[i].p[j]];
					for(int j=1;j<=n;j++) t1.p[j]=t2.p[j];
				}
			Find(0,t1,1);
		}
		printf("%d\n",ecnt[0]);
		return 0;
	}
	for(int i=1;i<=n;i++) t1.p[i]=i;
	Find(0,t1,0);
	for(int i=1;i<=m;i++){
		int i1=i-1&1,i2=i&1;
		for(int j=1;j<=ecnt[i1];j++){
			t1=e[i1][j].v,k=e[i1][j].k;
			for(int k=1;k<=n;k++) 
				t2.p[k]=t1.p[A[i].p[k]];
			Find(i2,t1,k),Find(i2,t2,1);
		}
		for(int j=1;j<=ecnt[i1];j++)
			head[i1][e[i1][j].v.val()]=0;
		ecnt[i1]=0;
	}
	int ans=0;
	for(int i=1;i<=ecnt[m&1];i++)
		if(e[m&1][i].k) ans++;
	printf("%d\n",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

5 4
1 2 3 4 5
5 1 3 4 2
3 4 1 5 2
5 2 4 1 3

output:


result: