QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#277314 | #7882. Linguistics Puzzle | Rachel_in# | WA | 2ms | 3836kb | C++14 | 1.5kb | 2023-12-06 17:39:09 | 2023-12-06 17:39:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int T,n,m,ans[10050],num[10050],to[100][100],haveAns;
bool vis[10050];
int l[10050],r[10050],c[10050];
int ll[10050],rr[10050],cc[10050];
vector<int>v[100];
void dfs(int x)
{
if(x==n)
{
haveAns=1;
for(int i=0;i<n;i++)ans[num[i]]=i;
return;
}
if(haveAns)return;
for(int i=0;i<v[x].size();i++)
{
int y=v[x][i];
if(!vis[y])
{
vis[y]=1;
num[x]=y;
dfs(x+1);
vis[y]=0;
}
}
}
int main()
{
cin>>T;
while(T--)
{
cin>>n;
haveAns=0;
for(int i=0;i<n;i++)v[i].clear();
for(int i=0;i<n;i++)l[i]=r[i]=c[i]=ll[i]=rr[i]=cc[i]=0;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
to[i][j]=0;
if(i*j<n)c[i*j]++;
else
{
l[i*j/n]++;
r[i*j%n]++;
}
}
for(int i=0;i<n*n;i++)
{
char s[10];
scanf("%s",s);
int len=strlen(s);
if(len==1)
{
int x=s[0]>='a'?s[0]-'a':s[0]-'A'+26;
cc[x]++;
}
else
{
int x=s[0]>='a'?s[0]-'a':s[0]-'A'+26;
int y=s[1]>='a'?s[1]-'a':s[1]-'A'+26;
ll[x]++;
rr[y]++;
}
}
// for(int i=0;i<n;i++)printf("%d %d %d\n",l[i],r[i],ll[i]);
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
if(l[i]==ll[j]&&r[i]==rr[j]&&c[i]==cc[j])
{
to[j][i]=1;
// printf("%d %d\n",i,j);
v[j].push_back(i);
}
}
dfs(0);
for(int i=0;i<n;i++)
{
printf("%c",ans[i]<26?'a'+ans[i]:'A'+ans[i]-26);
}
puts("");
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3588kb
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: 3836kb
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: 2ms
memory: 3684kb
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 The product 7*7=49 is not in the output at case #28