QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#237863#7687. Randias Permutation Taskucup-team958#RE 0ms0kbC++141.4kb2023-11-04 15:12:172023-11-04 15:12:18

Judging History

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

  • [2023-11-04 15:12:18]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-11-04 15:12:17]
  • 提交

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[maxn];
	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;
	}
};
struct node{
	pre v;
	int k,to;
}e[maxs];
int head[P],ecnt;
int Find(pre &x,int k){
	int v=x.val();
	for(int i=head[v];i;i=e[i].to)
		if(e[i].v==x&&e[i].k==k) return i;
	e[++ecnt].v=x,e[ecnt].k=k;
	e[ecnt].to=head[v],head[v]=ecnt;
}
struct PRE{
	int p[maxn];
	bool operator <(PRE x)const{
		for(int i=1;i<=n;i++)
			if(p[i]<x.p[i]) return 1;
			else if(p[i]>x.p[i]) return 0;
		return 0;
	}
};
map<PRE,bool>M;
int A[maxn][maxn];
int main(){
	n=read(),m=read();
	for(int i=1;i<=m;i++)
		for(int j=1;j<=n;j++)
			A[i][j]=read();
	int k,cnt;
	pre t1,t2;
	for(int i=1;i<=n;i++) t1.p[i]=i;
	Find(t1,0);
	for(int i=1;i<=m;i++){
		cnt=ecnt;
		for(int j=1;j<=cnt;j++){
			t1=e[j].v,k=e[j].k;
			for(int k=1;k<=n;k++) 
				t2.p[k]=t1.p[A[i][k]];
			Find(t1,k),Find(t2,1);
		}
	}
	int ans=0;
	for(int i=1;i<=ecnt;i++)
		if(e[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: