QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#626425#7882. Linguistics PuzzleMarch_AprilTL 1ms3972kbC++172.7kb2024-10-10 08:31:132024-10-10 08:31:13

Judging History

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

  • [2024-10-10 08:31:13]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3972kb
  • [2024-10-10 08:31:13]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

const int N = 55;

string s[N * N];

void work()
{
    char res[60] = { 0 };
    int n;
    cin >> n;

    for(int i = 0; i < n * n; i ++)
        cin >> s[i];

    vector<int> fuck(3000, 0);
    vector<int> cnt(n, 0);

    for(int i = 0; i < n; i ++)
        for(int j = 0; j < n; j ++)
        {
            int val = i * j;
            fuck[val] ++;

            if(!val)    cnt[val] ++;
            while(val)
                cnt[val % n] ++, val /= n;
        }

    vector<int> M(500, 0);

    for(int i = 0; i < n * n; i ++)
        for(int j = 0; j < (int)s[i].size(); j ++)
            M[s[i][j]] ++;

    vector<char> M1[5100];

    vector<int> M3[5100];
    vector<int> cnm;

    for(int x = 0; x < 500; x ++)
    {
        int y = M[x];
        // for(auto [x, y] : M)
        M1[y].push_back(x);
    }


    for(int x = 0; x < 5100; x ++)
    {
        vector<char> y = M1[x];
        if(!y.size())   continue;
        cnm.push_back(x);
        for(int j = 0; j < (int)y.size();j ++)
            M3[x].push_back(j);
    }


    auto ok = [&]()
        {
            vector<int> M2(5100, 0);
            for(int x : cnm)
                M2[x] = 0;

            vector<int> zhi(500, 0);

            for(int i = 0; i < n; i ++)
            {
                int t = M3[cnt[i]][M2[cnt[i]]];
                res[i] = M1[cnt[i]][t];
                M2[cnt[i]] ++;

                zhi[res[i]] = i;
            }

            vector<int> fuck1(3000, 0);

            for(int i = 0;i < n * n; i ++)
            {
                int val = 0;
                for(int j = 0; j < (int)s[i].size(); j ++)
                    val = val * n + zhi[s[i][j]];

                fuck1[val] ++;
            }

            for(int i = 0; i < fuck1.size(); i ++)
                if(fuck1[i] != fuck[i])
                    return false;
            return true;
        };

    bool flag = false;
    auto dfs = [&](auto dfs, int u)-> void
        {
            if(flag)    return;
            if(u == cnm.size())
            {
                if(ok())
                {
                    for(int i = 0; i < n; i ++)
                        cout << res[i];
                    puts("");

                    flag = true;
                    return;
                }
                return;
            }

            dfs(dfs, u + 1);
            next_permutation(M3[cnm[u]].begin(), M3[cnm[u]].end());
            dfs(dfs, u + 1);
        };

    dfs(dfs, 0);
}

int main()
{
    int T;
    cin >> T;

    while(T --)
        work();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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
Time Limit Exceeded

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: