QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#626413#7882. Linguistics PuzzleMarch_AprilTL 0ms3896kbC++172.4kb2024-10-10 08:13:122024-10-10 08:13:13

Judging History

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

  • [2024-10-10 08:13:13]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3896kb
  • [2024-10-10 08:13:12]
  • 提交

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];

    map<int, int> fuck;
    vector<int> cnt(n * n + 10, 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;
        }

    map<char, int> M;

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

    map<int, vector<char>> M1;

    map<int, vector<int>> M3;
    vector<int> cnm;

    for(auto [x, y] : M)
        M1[y].push_back(x);

    for(auto [x, y] : M1)
    {
        cnm.push_back(x);
        for(int j = 0; j < (int)y.size();j ++)
            M3[x].push_back(j);
    }


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

            map<char, int> zhi;

            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;
            }

            map<int, int> fuck1;

            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] ++;
            }

            return fuck1 == fuck;
        };

    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: 0ms
memory: 3640kb

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

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: