QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#592824#7882. Linguistics PuzzleJZYZ#WA 11ms5352kbC++141.9kb2024-09-27 08:27:562024-09-27 08:27:58

Judging History

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

  • [2024-09-27 08:27:58]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:5352kb
  • [2024-09-27 08:27:56]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 200;
string a[N*N];
int n,m;
int digit[N];
char ch[N];
char ans[N];
mt19937 rnd(time(0));
int cnt[N*N];
map<string,int> mp;
bool chk(int x,char c)
{
    string u;u+=c;
    if(cnt[x]!=mp[u])return 0;
    if(cnt[x*n+x]!=mp[u+u])return 0;
    for(int i=0;i<x;i++)
    {
        string g;g+=ans[i];
        string t=u+g;
        if(cnt[x*n+i]!=mp[t])return 0;
        if(i>0)
        {
            t=g+u;
            if(cnt[i*n+x]!=mp[t])return 0;
        }
    }
    return 1;
}
bool flag=0;
void dfs(int x)
{
    if(x==n)
    {
        for(int i=0;i<n;i++)cout<<ans[i];cout<<endl;
        flag=1;return;
    }
    for(int i=1;i<=n;i++)if(digit[ch[i]]==-1)
    {
        if(chk(x,ch[i])==0)continue;
        digit[ch[i]]=x;
        ans[x]=ch[i];
        dfs(x+1);
        digit[ch[i]]=-1;
        if(flag)return;
    }
}
void solve()
{
    cin>>n;m=n*n;
    mp.clear();memset(cnt,0,sizeof(cnt));
    for(int i=1;i<=n*n;i++)cin>>a[i],mp[a[i]]++;
    for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
    cnt[i*j]++;
    memset(digit,-1,sizeof(digit));
    for(int i=1;i<=n;i++)
    {
        if(i<=26)ch[i]='a'+i-1;
        else ch[i]='A'+i-n-1;
    }
    int mn=1e9,mx=-1e9;
    for(int i=1;i<=n*n;i++)
    {
        if(a[i].size()>1)continue;
        mn=min(mn,mp[a[i]]);
        mx=max(mx,mp[a[i]]);
    }
    for(int i=1;i<=n*n;i++)
    {
        if(a[i].size()>1)continue;
        if(mp[a[i]]==mn)
        {
            ans[1]=a[i][0];
            digit[a[i][0]]=1;
        }
        else if(mp[a[i]]==mx)
        ans[0]=a[i][0],digit[a[i][0]]=0;
    }
    shuffle(ch+1,ch+n+1,rnd);
    dfs(2);

}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
	return 0;
}
/*
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
*/

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 4960kb

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: 1ms
memory: 5284kb

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

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 output format Unexpected end of file - token expected