QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#275935#7882. Linguistics Puzzlepengpeng_fudanWA 2ms3792kbC++142.4kb2023-12-05 12:34:482023-12-05 12:34:49

Judging History

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

  • [2023-12-05 12:34:49]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3792kb
  • [2023-12-05 12:34:48]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
using ll=long long;
struct node{
    int a=0,b=0,c=0,d=0;
    bool operator==(node x){
        return a==x.a&&b==x.b&&c==x.c&&d==x.d;
    }
    void pt(){
        cout<<a<<' '<<b<<' '<<c<<' '<<d<<'\n';
    }
};
node ct[60][2];
int n;
char fget(int x){
    if(x<n) return 'a'+x;
    else return 'A'+x-26;
}
int get(char c){
    if(c<='z'&&c>='a')  return c-'a';
    else return c-'A'+26;
}
int ans[60];
bool flag[60];
int num[10010];
int zt[10010];
bool check(){
    copy(num,num+52*52+1,zt);
    //for(int i=0;i<n;i++)    cout<<fget(ans[i]);
    //cout<<'\n';
    for(int a=0;a<n;a++){
        for(int b=0;b<n;b++){
            int i=a*b;
            if(i<n){
                zt[ans[i]]--;
                if(zt[ans[i]]<0) return false;
            }
            else{
                zt[ans[i/n]*n+ans[i%n]]--;
                if(zt[ans[i/n]*n+ans[i%n]]<0)   return false;
            }
        }
    }
    return true;
}
bool dfs(int x){
    if(x==n)    return check();
    for(int i=0;i<n;i++){
        if(!flag[i]&&ct[i][0]==ct[x][1]){
            flag[i]=1;
            ans[x]=i;
            if(dfs(x+1))    return true;
            flag[i]=0;
            ans[x]=0;
        }
    }
    return false;
}

void solve() {
    cin>>n;
    string s;
    fill(num,num+52*52+1,0);
    fill(flag,flag+n+1,0);
    for(int i=0;i<=n;i++){
        ct[i][0].a=ct[i][0].b=ct[i][0].c=ct[i][0].d=0;
        ct[i][1].a=ct[i][1].b=ct[i][1].c=ct[i][1].d=0;
    }
    for(int i=0;i<=n*n-1;i++){
        cin>>s;
        if(s.size()==1){
            ct[get(s[0])][0].c++;
            num[get(s[0])]++;
        }
        else{
            ct[get(s[0])][0].a++;
            ct[get(s[1])][0].b++;
            if(s[0]==s[1])  ct[get(s[0])][0].d++;
            num[get(s[0])*n+get(s[1])]++;
        }
    }
    for(int a=0;a<n;a++){
        for(int j=0;j<n;j++){
            int i=a*j;
            if(i<n) ct[i][1].c++;
            else{
                ct[i/n][1].a++;
                ct[i%n][1].b++;
                if(i/n==i%n)    ct[i%n][1].d++;
            }

        }
    }
    dfs(0);

    for(int i=0;i<n;i++)    cout<<fget(ans[i]);
    cout<<'\n';
}
int main() {
    ios::sync_with_stdio(0),cin.tie(0);
    int _ = 1;
    cin >> _;
    while(_--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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