QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#564878#7882. Linguistics PuzzleBird#RE 0ms3868kbC++171.5kb2024-09-15 16:28:392024-09-15 16:28:40

Judging History

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

  • [2024-09-15 16:28:40]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3868kb
  • [2024-09-15 16:28:39]
  • 提交

answer

#include<bits/stdc++.h>
#define N 52
using namespace std;
int n,cnt[N],num[N],val[N*N],to[N];
int v1[N],v2[N][N];
vector<int> v[N*N];
char s[N+5];
inline int char_int(char ch)
{
	if('a'<=ch && ch<='z') return ch-'a';
	return ch-'A';
}
inline char int_char(int ch)
{
	if(ch<26) return 'a'+ch;
	return 'A'+ch;
}
bool vis[N];
bool check()
{
	for(int i=0;i<n;++i)
		if(v1[i]!=val[to[i]]) return 0;
	for(int i=0;i<n;++i) if(to[i]!=0)
		for(int j=0;j<n;++j)
			if(v2[i][j]!=val[to[i]*n+to[j]])
				return 0;
	return 1;
}
bool dfs(int i)
{
	if(i==n) return check();
	for(int x:v[cnt[i]]) if(!vis[x])
	{
		to[i]=x,vis[x]=1;
		if(dfs(i+1)) return 1;
		vis[x]=0;
	}
	return 0;
}
int main()
{
	int T;
	for(scanf("%d",&T);T--;)
	{
		scanf("%d",&n);
		memset(v1,0,sizeof v1);
		memset(v2,0,sizeof v2);
		memset(cnt,0,sizeof cnt);
		memset(num,0,sizeof num);
		memset(val,0,sizeof val);
		for(int i=0;i<n*n;++i)
		{
			scanf("%s",s);
			if(s[1])
			{
				int s0=char_int(s[0]),s1=char_int(s[1]);
				++v2[s0][s1],++cnt[s0],++cnt[s1];
			}
			else
			{
				int s0=char_int(s[0]);
				++v1[s0],++cnt[s0];
			}
		}
		for(int i=0;i<n;++i)
			for(int j=0;j<n;++j)
			{
				int x=i*j;
				++val[x];
				if(x/n) ++num[x/n];
				++num[x%n];
			}
		for(int i=0;i<n;++i)
			v[num[i]].push_back(i);
		memset(vis,0,sizeof vis);
		assert(dfs(0));
		for(int i=0;i<n;++i)
			v[num[i]].clear();
		for(int i=0;i<n;++i) s[to[i]]=int_char(i);
		s[n]=0,printf("%s\n",s);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3864kb

input:

2
3
a b a b b b b c cc
4
d d d d d c b a d b cd cb d a cb bc

output:

bca
dcba

result:

ok OK

Test #2:

score: 0
Accepted
time: 0ms
memory: 3868kb

input:

2
4
d a a bc ba bc b a a a d a a cb c c
4
a b da b b d ad b db b a c da b c b

output:

abcd
bdac

result:

ok OK

Test #3:

score: -100
Runtime Error

input:

50
3
b b b a a c b b cc
4
d ab c ad d b ba ab c b d d d d d a
5
a aa aa ab ab ae b b e c c c ba c c c c dd d d dd c e c e
6
a ca a a a a a a ce a a b ba ba bc bc bd be e c c ca a cd cd be d d dc dc e e a eb f f
7
a a a a a a a a cf a a a a b b b b c c c cf a dd d dc d dd e f ed ee ee fb eg eg eg eg ...

output:


result: