QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#669190#7882. Linguistics PuzzleNightskyWA 2ms3908kbC++142.4kb2024-10-23 17:37:192024-10-23 17:37:20

Judging History

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

  • [2024-10-23 17:37:20]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3908kb
  • [2024-10-23 17:37:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 55;
int n;
int cnt[MAXN][3],tar[MAXN][3],res[MAXN],c[MAXN*MAXN],t[MAXN*MAXN],ans[MAXN];
char S[MAXN*MAXN][5];
bool vis[MAXN];
int trans(char x)
{
    if('a'<=x&&x<='z') return x-'a';
    else return x-'A'+26;
}
char Itrans(int x)
{
    if(x<26) return 'a'+x;
    else return 'A'+x;
}
bool check()
{
    for(int i=0;i<n*n;++i) c[i]=0;
    for(int i=1;i<=n*n;++i)
    {
        int len=strlen(S[i]+1),tmp=0;
        for(int j=1;j<=len;++j) tmp=tmp*n+res[trans(S[i][j])];
        if(len>=2&&res[trans(S[i][1])]==0) return false;
        c[tmp]++;
    }
    for(int i=0;i<n*n;++i) if(t[i]!=c[i]) return false;
    return true;
}
bool dfs(int p)
{
    if(p==n)
    {

        return true;

        // cout<<"thisyes"<<endl;

        // if(check()) return true;
        // else return false;
    }
    for(int i=0;i<n;++i)
    {
        if(vis[i]) continue;
        if(cnt[i][0]!=tar[p][0]||cnt[i][1]!=tar[p][1]||cnt[i][2]!=tar[p][2]) continue;
        ans[p]=i;
        res[i]=p;
        vis[i]=1;
        if(dfs(p+1)) return true;
        vis[i]=0;
    }
    return false;
}

int main()
{
    int T;scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);

        for(int i=0;i<n;++i) vis[i]=0;
        for(int i=0;i<n;++i)
            for(int j=0;j<=2;++j) cnt[i][j]=tar[i][j]=0;
        for(int i=0;i<n*n;++i) c[i]=t[i]=0;
        
        for(int i=1;i<=n*n;++i)
        {
            scanf("%s",S[i]+1);
            int len=strlen(S[i]+1);
            if(len>=2)
            {
                cnt[trans(S[i][1])][0]++;
                cnt[trans(S[i][2])][1]++;
                if(S[i][1]==S[i][2]) cnt[trans(S[i][1])][2]++;
            }
            else cnt[trans(S[i][1])][1]++;
        }

        for(int i=0;i<n;++i)
        {
            for(int j=0;j<n;++j)
            {
                int tmp=i*j;
                t[tmp]++;
                
                if(tmp>=n)
                {
                    tar[tmp/n][0]++;
                    tar[tmp%n][1]++;
                    if(tmp/n==tmp%n) tar[tmp%n][2]++;
                }
                else tar[tmp][1]++;
            }
        }

        // cout<<cnt[0

        // if(dfs(0)) cout<<"yes"<<endl;
        // else cout<<"no"<<endl;

        dfs(0);

        for(int i=0;i<n;++i) putchar(Itrans(ans[i]));
        printf("\n");
    }
    return 0;
}

詳細信息

Test #1:

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

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: 3908kb

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: 3872kb

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 [ at case #25