QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#617771 | #7882. Linguistics Puzzle | hjxddl | WA | 7ms | 3920kb | C++20 | 2.8kb | 2024-10-06 17:00:49 | 2024-10-06 17:00:53 |
Judging History
answer
// Coded by hjxddl
#include <bits/stdc++.h>
#define ll long long
#define db double
#define v(x) std::vector<x>
const int N = 2e5 + 5;
int ans[60], n;
int ans1[60][60];
std::string s[60][60];
std::map<std::pair<int, int>, v(int)> mp;
std::map<char, int> id;
std::map<int, char> rid;
v(int) cnt(2600);
v(int) cnt1, cnt2, cnt3, cnt4;
bool dfs(int x) {
if (x == n + 1) {
v(int) cnt5 = cnt;
int ans2[60];
for (int i = 0; i < n; i++) {
ans2[ans[i]] = i;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (s[i][j].size() == 1) {
cnt5[ans2[id[s[i][j][0]]]]--;
} else {
cnt5[ans2[id[s[i][j][0]]] * n + ans2[id[s[i][j][1]]]]--;
}
}
}
for (int i = 0; i <= n * n; i++)
if (cnt5[i]) return 0;
return 1;
}
v(int) &num = mp[{cnt3[x], cnt4[x]}];
for (auto &y : num) {
// std::cerr << x << " " << y << " " << ans[y] << '\n';
if (ans[y]) continue;
ans[y] = x;
if (dfs(x + 1)) return 1;
ans[y] = 0;
}
return 0;
}
void init() {
for (int i = 0; i < n; i++)
ans[i] = 0;
mp.clear();
cnt = v(int)(2600);
cnt1 = cnt2 = cnt3 = cnt4 = v(int)(n + 5);
}
void solve() {
std::cin >> n;
init();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
std::cin >> s[i][j];
cnt1[i * j % n]++;
if (i * j / n)
cnt2[i * j / n]++;
cnt[i * j]++;
if (s[i][j].size() == 1) {
cnt3[id[s[i][j][0]]]++;
} else {
cnt3[id[s[i][j][1]]]++;
cnt4[id[s[i][j][0]]]++;
}
}
}
for (int i = 0; i < n; i++)
mp[{cnt1[i], cnt2[i]}].push_back(i);
// for (auto [_, x] : mp) {
// for (auto it : x) {
// std::cerr << it << " " << _.first << " " << _.second << '\n';
// }
// }
// for (int i = 1; i <= n; i++) {
// std::cerr << i << " " << cnt3[i] << " " << cnt4[i] << '\n';
// }
dfs(1);
for (int i = 0; i < n; i++) {
std::cout << rid[ans[i]];
}
std::cout << '\n';
}
int main() {
std::ios::sync_with_stdio(0);
std::cin.tie(0), std::cout.tie(0);
for (int i = 0; i <= 25; i++) {
id['a' + i] = i + 1;
rid[i + 1] = char('a' + i);
}
for (int i = 26; i <= 51; i++) {
id['A' + i - 26] = i + 1;
rid[i + 1] = char('A' + i - 26);
}
int t = 1;
std::cin >> t;
while (t--) {
solve();
}
std::cout << std::flush;
// system("pause");
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
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: 3920kb
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: 7ms
memory: 3656kb
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:
wrong answer invalid character