QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#269275#7882. Linguistics Puzzleucup-team2303#WA 11ms48864kbC++143.6kb2023-11-29 14:39:052023-11-29 14:39:05

Judging History

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

  • [2023-11-29 14:39:05]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:48864kb
  • [2023-11-29 14:39:05]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long T,a,b,c,d[1000001],v[1000001],o,h[1000001],fa[1000001],q,w,e,an[1000001],cn,fac[1000001],inv[1000001],st[1000001],u[1000001],v1[101][101],v2[101][101],vv[1000001];
long long v3[1000001],v4[1000001],vv3[1000001],vv4[1000001],id[1000001],t[1001][1001],v5[1001][1001],an1[1000001];
char s[1000001];
struct p{long long q,w,e;bool operator < (const p &aa) const{if(w==aa.w&&q==aa.q) return e<aa.e;if(q==aa.q) return w<aa.w;return q<aa.q;};}l[1000001];
map<p,long long> ve;
long long pow_(long long qq,long long ww){long long ee=1;while(ww){if(ww&1) ee*=qq,ee%=mod;qq*=qq,qq%=mod,ww>>=1;}return ee%mod;}
inline int read(){int x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}return x*f;}
void add(long long qq,long long ww){l[++o].q=ww,l[o].w=h[qq],h[qq]=o;}
long long gcd(long long qq,long long ww){return !ww?qq:gcd(ww,qq%ww);}
long long find(long long qq){return qq==fa[qq]?qq:fa[qq]=find(fa[qq]);}
void merge(long long qq,long long ww){long long f1=find(qq),f2=find(ww);if(f1==f2) return;fa[f1]=f2;}
long long C(long long qq,long long ww){return fac[qq]*inv[ww]%mod*inv[qq-ww]%mod;}
vector<long long> qu[10001];
bool fll=0;
void dfs(long long qq)
{
	if(qq>=a)
	{
		bool fl1=1;
		for(int i=0;i<a;i++)
		{
			for(int j=0;j<a;j++)
			{
//				cout<<v2[an[i]][an[j]]<<" "<<v1[i][j]<<"\n";
				if(v2[i][j]!=v1[an[i]][an[j]])
				{
					fl1=0;
				}
			}
		}
		if(fl1)
		{
			fll=1;
		}
		return;
	}
	for(int i=0;i<qu[id[qq]].size();i++)
	{
		if(!t[id[qq]][i])
		{
			an[qq]=qu[id[qq]][i];
			t[id[qq]][i]=1;
			dfs(qq+1);
			t[id[qq]][i]=0;
			if(fll) return;
		}
	}
}
char cc;
int main()
{
//	freopen("1.in","r",stdin);
	srand((unsigned)(time(0)^(*new int)));
	fac[0]=1;for(int i=1;i<=1000000;i++) fac[i]=fac[i-1]*i%mod;
	inv[1000000]=pow_(fac[1000000],mod-2);for(int i=999999;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
	T=1;
	scanf("%lld",&T);
	for(int ii=1;ii<=T;ii++)
	{
		scanf("%lld",&a);cn=0;
		for(int i=0;i<a;i++)
		{
			for(int j=0;j<a;j++)
			{
				st[++cn]=i*j;
			}
		}
		for(int i=0;i<=a*a;i++) v[i]=vv[i]=v3[i]=vv3[i]=v4[i]=vv4[i]=0;
		for(int i=0;i<=a;i++) for(int j=0;j<=a;j++) v1[i][j]=v2[i][j]=0;
		for(int i=1;i<=cn;i++)
		{
			if(st[i]<a)
			{
				v[st[i]]++;
			}
			else
			{
				v1[st[i]/a][st[i]%a]++;
				v3[st[i]/a]++,v4[st[i]%a]++;
			}
		}
		for(int i=1;i<=a*a;i++)
		{
			scanf("%s",s+1);
			b=strlen(s+1);
			long long gg=0,g1=0;
			if(b==1)
			{
				if(s[1]<='Z') gg=26+s[1]-'A';
				else gg=s[1]-'a';
				vv[gg]++;
			}
			else
			{
				if(s[1]<='Z') gg=26+s[1]-'A';
				else gg=s[1]-'a';
				if(s[2]<='Z') g1=26+s[2]-'A';
				else g1=s[2]-'a';
				v2[gg][g1]++;
				vv3[gg]++,vv4[g1]++;
//				cout<<gg<<" "<<g1<<"\n";
			}
//			cout<<i<<" "<<b<<"\n";
		}
		for(int i=0;i<a;i++)
		{
			l[i]=p{v[i],v3[i],v4[i]};
//			cout<<v[i]<<" "<<v3[i]<<" "<<v4[i]<<"\n";
		}
		ve.clear();cn=0;
		for(int i=1;i<=a;i++) qu[i].clear();
		for(int i=0;i<a;i++)
		{
			if(!ve[l[i]]) ve[l[i]]=++cn;
			qu[cn].push_back(i);
		}
		for(int i=0;i<a;i++)
		{
//			cout<<vv[i]<<" "<<vv3[i]<<" "<<vv4[i]<<"\n";
			id[i]=ve[p{vv[i],vv3[i],vv4[i]}];
//			cout<<id[i]<<" ";
		}fll=0;
		for(int i=0;i<=a;i++) for(int j=0;j<=a;j++) t[i][j]=0;
		dfs(0);
//		cout<<fll<<" ";
		for(int i=0;i<a;i++)
		{
			an1[an[i]]=i;
		}
		for(int i=0;i<a;i++)
		{
			if(an1[i]<26)
			{
				cc=an1[i]+'a';
			}
			else cc=an1[i]+'A'-26;
			putchar(cc);
		}printf("\n");
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 46664kb

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: 11ms
memory: 44732kb

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
Wrong Answer
time: 9ms
memory: 48864kb

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:

bca
dabc
cadbe
abcdef
aefdcgb
fcheabgd
bhgfedcia
jhcgfideba
fjbadkegcih
klhgjbaedcif
igkjmclfedhba
nflijahgmbdcek
anmlfijbgkhdceo
nofmlkjchdbegipa
aponblgjihcfqdkme
iqmonhckfrpgjedlba
prisodmbkjqghfencla
tcrdpoaklmjihfgeqsbn
utiraponmlksghjfecdbq
qotsrvjunmlkpiegfhdcba
pvutsrhwoimlkjnqgfedbca
xbvuts...

result:

wrong answer invalid character k at case #28