QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#617636 | #7882. Linguistics Puzzle | hjxddl | WA | 1ms | 3912kb | C++20 | 2.2kb | 2024-10-06 16:28:53 | 2024-10-06 16:28:54 |
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;
std::map<std::pair<int, int>, v(int)> mp;
std::map<char, int> id;
std::map<int, char> rid;
v(int) cnt1, cnt2, cnt3, cnt4;
bool dfs(int x) {
if (x == n + 1)
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();
cnt1 = cnt2 = cnt3 = cnt4 = v(int)(n + 5);
}
void solve() {
std::cin >> n;
init();
std::string s[n + 5][n + 5];
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]++;
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;
return 0;
// system("pause");
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
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: 3604kb
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: 1ms
memory: 3912kb
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 prisdombkjqghfencla tcrdpoaklmjihfgeqsbn utiraponmlksghjfecdbq qotsrvjunmlkpiegfhdcba pvutsrhwoimlkjnqgfedbca xbvuts...
result:
wrong answer The product 2*12=24 is not in the output at case #17