QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#279102#7882. Linguistics PuzzleSGColinRE 0ms0kbC++202.2kb2023-12-08 11:03:462023-12-08 11:03:46

Judging History

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

  • [2023-12-08 11:03:46]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-12-08 11:03:46]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tiii;

#define eb emplace_back
#define all(s) (s).begin(), (s).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)

int n, t, T;

vector<char> sc[60];

bool use[256], vis[3007];

char ans[60];

int tr(char c) {return islower(c) ? c - 'a' : c - 'A' + 26;}

bool check() {
    rep(i, 0, n - 1) rep(j, 0, n - 1) {
        int w = i * j;
        if (w < n) if (!vis[tr(ans[w])]) return false;
        else if (!vis[tr(ans[w / n]) * 53 + tr(ans[w % n])]) return false;
    }
    return true;
}

bool dfs(int pos) {
    if (pos == n) return check();
    for (auto x : sc[pos]) 
        if (!use[x]) {
            use[x] = true;
            ans[pos] = x;
            if (dfs(pos + 1)) return true;
            use[x] = false;
        }
    return false;
}

inline void work() {
    cin >> n;
    memset(vis, 0, sizeof(vis));
    memset(use, 0, sizeof(use));
    vector<int> cnt1(n, 0), cnt2(n, 0), cntb(n, 0);
    rep(i, 0, n - 1) rep(j, 0, n - 1) {
        int w = i * j;
        ++cnt2[w % n];
        if (w >= n) {
            ++cnt1[w / n];
            if (w / n == w % n) ++cntb[w / n];
        }
    }
    map<tiii, vector<int>> f;
    rep(i, 0, n - 1) f[{cnt1[i], cnt2[i], cntb[i]}].push_back(i);

    map<char, int> c1, c2, cb;
    set<char> ch;
    rep(i, 1, n * n) {
        string s; cin >> s;
        if (t == 21) cout << s << " ";
        int l = s.length();
        if (l == 1) {
            ++c2[s[0]]; ch.insert(s[0]);
            vis[tr(s[0])] = true;
        } else {
            ++c1[s[0]]; ch.insert(s[0]);
            ++c2[s[1]]; ch.insert(s[1]);
            vis[tr(s[0]) * 53 + tr(s[1])] = true;
            if (s[0] == s[1]) ++cb[s[0]];
        }
    }
    rep(i, 0, n - 1) sc[i].clear();
    for (auto x : ch) {
        tiii c = make_tuple(c1[x], c2[x], cb[x]);
        for (auto p : f[c]) sc[p].push_back(x);
    }
    dfs(0);
    if (T < 10 || t == 21) rep(i, 0, n - 1) putchar(ans[i]); puts("");
}

int main() {
    cin >> T;
    for (; t <= T; ++t) work();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

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: