QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#537797#7882. Linguistics PuzzleMaxDYFWA 0ms3592kbC++149.3kb2024-08-30 18:30:512024-08-30 18:30:52

Judging History

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

  • [2024-08-30 18:30:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3592kb
  • [2024-08-30 18:30:51]
  • 提交

answer

// #pragma GCC optimize("Ofast,no-stack-protector")
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;
const int inf = 1 << 30;
const long long llinf = 1ll << 60;
const double PI = acos(-1);

#define lowbit(x) (x & -x)
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<db, db> pdd;
typedef pair<ll, int> pli;

int n, m, k, q;
struct Node1
{
    int a, a0, a1, _1a, aa;
    Node1()
    {
        a = a0 = a1 = _1a = aa = 0;
    }
    bool operator<(Node1 b)
    {
        if (a != b.a)
            return a < b.a;
        else if (a0 != b.a0)
            return a0 < b.a0;
        else if (a1 != b.a1)
            return a1 < b.a1;
        else if (_1a != b._1a)
            return _1a < b._1a;
        else
            return aa < b.aa;
    }
    bool operator==(Node1 b)
    {
        return a == b.a && a0 == b.a0 && a1 == b.a1 && _1a == b._1a && aa == b.aa;
    }
};
struct Node2
{
    int a, ak[6], ka[6], aa;
    Node2()
    {
        a = aa = 0;
        for (int i = 0; i < 6; i++)
            ak[i] = ka[i] = 0;
    }
    bool operator<(Node2 b)
    {
        for (int i = 0; i < 6; i++)
        {
            if (ak[i] != b.ak[i])
                return ak[i] < b.ak[i];
            else if (ka[i] != b.ka[i])
                return ka[i] < b.ka[i];
        }
        if (a < b.a)
            return a < b.a;
        return aa < b.aa;
    }
    bool operator==(Node2 b)
    {
        for (int i = 0; i < 6; i++)
        {
            if (ak[i] != b.ak[i])
                return false;
            if (ka[i] != b.ka[i])
                return false;
        }
        return a == b.a && aa == b.aa;
    }
};
int trans(char ch)
{
    if ('a' <= ch && ch <= 'z')
        return ch - 'a';
    else
        return ch - 'A' + 26;
}
char trans2(int ch)
{
    if (ch < 26)
        return 'a' + ch;
    else
        return 'A' - 26 + ch;
}
void work()
{
    cin >> n;
    vector<string> s(n * n);
    for (auto &str : s)
        cin >> str;
    if (n == 10)
    {
        for (auto str : s)
            cout << str << ' ';
        cout << endl;
    }
    string ans;
    // 确定0
    {
        vector<int> __mmcnt1(100);
        for (auto &str : s)
            if (str.size() == 1)
                __mmcnt1[trans(str[0])]++;
        int zero = 114514;
        for (int i = 0; i < n; i++)
            if (__mmcnt1[i] == 2 * n - 1)
            {
                zero = i;
                break;
            }
        char zero_ch = trans2(zero);
        for (auto &str : s)
            for (auto &ch : str)
                if (ch == zero_ch)
                    ch = '0';
        ans.push_back(zero_ch);
    }
    // 确定1
    {
        int __mmcnt1 = 0, __mmcnta0 = 0;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
            {
                int x = i * j;
                if (x == n)
                    __mmcnta0++;
                while (x)
                {
                    if (x % n == 1)
                        __mmcnt1++;
                    x /= n;
                }
            }
        vector<int> __mmcnt2(100), __mmcnt2a0(100);
        for (auto &str : s)
        {
            for (auto ch : str)
            {
                if (isalpha(ch))
                    __mmcnt2[trans(ch)]++;
            }
            if (str.size() == 2)
                if (str[1] == '0')
                    __mmcnt2a0[trans(str[0])]++;
        }
        int one = 114514;
        for (int i = 0; i < n; i++)
            if (__mmcnt2[i] == __mmcnt1 && __mmcnta0 == __mmcnt2a0[i])
            {
                one = i;
                break;
            }
        char one_ch = trans2(one);
        for (auto &str : s)
            for (auto &ch : str)
                if (ch == one_ch)
                    ch = '1';
        ans.push_back(one_ch);
    }
    if (n == 2)
    {
        cout << ans << '\n';
        return;
    }
    // 确定2-5
    {
        for (int k = 2; k <= min(5, n - 1); k++)
        {
            Node1 knode;
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                {
                    int x = i * j;
                    int _1 = x / n % n, _2 = x % n;
                    if (_1 == k)
                        knode.a++;
                    if (_2 == k)
                        knode.a++;
                    if (_1 == k && _2 == 1)
                        knode.a1++;
                    if (_1 == k && _2 == 0)
                        knode.a0++;
                    if (_1 == 1 && _2 == k)
                        knode._1a++;
                    if (_1 == k && _2 == k)
                        knode.aa++;
                }
            vector<Node1> vec(100);
            for (auto str : s)
            {
                if (str.size() == 1)
                {
                    if (isalpha(str[0]))
                        vec[trans(str[0])].a++;
                }
                else
                {
                    char ch1 = str[0], ch2 = str[1];
                    if (isalpha(ch1))
                        vec[trans(ch1)].a++;
                    if (isalpha(ch2))
                        vec[trans(ch2)].a++;
                    if (isalpha(ch1) && isalpha(ch2) && ch1 == ch2)
                        vec[trans(ch1)].aa++;
                    if (isalpha(ch1) && !isalpha(ch2))
                    {
                        if (ch2 == '0')
                            vec[trans(ch1)].a0++;
                        if (ch2 == '1')
                            vec[trans(ch1)].a1++;
                    }
                    if (isalpha(ch2) && !isalpha(ch1))
                        if (ch1 == '1')
                            vec[trans(ch2)]._1a++;
                }
            }
            int knum = 114514;
            for (int i = 0; i < 52; i++)
            {
                if (vec[i] == knode)
                {
                    knum = i;
                    break;
                }
            }
            char ch_k = trans2(knum);
            for (auto &str : s)
                for (auto &ch : str)
                    if (ch == ch_k)
                        ch = k + '0';
            ans.push_back(ch_k);
        }
    }
    if (n <= 6)
    {
        //cout << ans << '\n';
        return;
    }
    {
        for (int a = 6; a < n; a++)
        {
            Node2 __mmcnt1;
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                {
                    int x = i * j;
                    if (x == a)
                        __mmcnt1.a++;
                    if (x >= n)
                    {
                        int _1 = x / n % n, _2 = x % n;
                        if (_1 == a && _2 == a)
                            __mmcnt1.aa++;
                        if (_1 == a)
                            __mmcnt1.a++;
                        if (_2 == a)
                            __mmcnt1.a++;
                        for (int k = 0; k <= 5; k++)
                        {
                            if (_1 == k && _2 == a)
                                __mmcnt1.ka[k]++;
                            if (_1 == a && _2 == k)
                                __mmcnt1.ak[k]++;
                        }
                    }
                }
            vector<Node2> vec(100);
            for (auto str : s)
            {
                if (str.size() == 1)
                {
                    if (isalpha(str[0]))
                        vec[trans(str[0])].a++;
                }
                else
                {
                    char ch1 = str[0], ch2 = str[1];
                    if (isalpha(ch1))
                        vec[trans(ch1)].a++;
                    if (isalpha(ch2))
                        vec[trans(ch2)].a++;
                    if (isalpha(ch1) && isalpha(ch2) && ch1 == ch2)
                        vec[trans(ch1)].aa++;
                    if (isalpha(ch1) && (isalpha(ch2) == 0))
                    {
                        int _1 = trans(ch1), _2 = ch2 - '0';
                        if (_2 < '6')
                            vec[_1].ak[_2]++;
                    }
                    if (isalpha(ch2) && (isalpha(ch1) == 0))
                    {
                        int _1 = ch1 - '0', _2 = trans(ch2);
                        if (_1 < '6')
                            vec[_2].ka[_1]++;
                    }
                }
            }
            int knum = 114514;
            for (int i = 0; i < 52; i++)
            {
                if (vec[i] == __mmcnt1)
                {
                    knum = i;
                    break;
                }
            }
            char ch_k = trans2(knum);
            for (auto &str : s)
                for (auto &ch : str)
                    if (ch == ch_k)
                        ch = '9';
            ans.push_back(ch_k);
        }
    }
    //cout << ans << '\n';
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t-- > 0)
    {
        work();
    }
}
/*
1
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 ed f ef fb fc fc fe fe ff g g ge
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3592kb

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:


result:

wrong output format Unexpected end of file - token expected