QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#272537#7882. Linguistics Puzzleucup-team956#WA 10ms3624kbC++202.1kb2023-12-02 17:44:002023-12-02 17:44:01

Judging History

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

  • [2023-12-02 17:44:01]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:3624kb
  • [2023-12-02 17:44:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
    int n;
    cin>>n;
    vector<int> dsr;
    for(int i=0;i<n;++i)
        for(int j=0;j<n;++j)
            dsr.push_back(i*j);
    sort(dsr.begin(),dsr.end());
    vector<string> a(n*n);
    for(auto& s:a) cin>>s;

    map<int,array<int,2>> E;
    for(int i=0;i<n;++i) {
        for(int j=0;j<n;++j) {
            int val=i*j;
            if(val/n) E[val/n][1]++;
            E[val%n][0]++;
        }
    }
    map<array<int,2>,vector<int>> EE;
    for(auto [x,y]:E) EE[y].push_back(x);

    map<char,array<int,2>> Q;
    for(auto s:a) {
        if(s.length()==1) {
            Q[s[0]][0]++;
        } else {
            Q[s[0]][1]++;
            Q[s[1]][0]++;
        }
    }
    map<array<int,2>,vector<char>> QQ;
    for(auto [x,y]:Q) QQ[y].push_back(x);

    vector<char> ans(n);
    vector<int> inv_ans(255);

    auto check=[&]() -> bool {
        vector<int> res;
        
        for(auto& x:a) {
            if(x.length()==1) {
                res.push_back(inv_ans[x[0]]);
            } else {
                res.push_back(inv_ans[x[0]]*n+inv_ans[x[1]]);
            }
        }
        sort(res.begin(),res.end());
        return dsr==res;
    };
    vector<array<int,2>> I;
    for(auto [x,y]:QQ) I.push_back(x); 

    auto dfs=[&](auto dfs,int i) -> int {
        if(i==I.size()) {
            return check();
        }
        array<int,2> x=I[i];
        auto A=QQ[x];
        auto B=EE[x];
        // QQ[x] EE[x];
        vector<int> p(QQ[x].size());
        for(int i=0;i<p.size();++i) p[i]=i;
        do {
            for(int i=0;i<B.size();++i) {
                ans[B[i]]=A[p[i]];
                inv_ans[A[p[i]]]=B[i];
            }
            if(dfs(dfs,i+1)) return 1;
        } while(next_permutation(p.begin(),p.end()));
        return 1;
    };
    dfs(dfs,0);
    for(int i=0;i<n;++i) cout<<ans[i];
    cout<<"\n";
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0); 

    int t;cin>>t;
    while(t--) solve();    
    return 0; 
}

詳細信息

Test #1:

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

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

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: 10ms
memory: 3624kb

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
prisdombkjqghfencla
tcrdpoaklmjihfgeqsbn
utiraponmlksghjfecdbq
qotsrvjunmlkpiegfhdcba
pvutsrhwoimlkjnqgfedbca
xbvuts...

result:

wrong answer The product 2*12=24 is not in the output at case #17