QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#288463 | #7882. Linguistics Puzzle | ckiseki# | WA | 3ms | 3924kb | C++20 | 2.4kb | 2023-12-22 18:18:00 | 2023-12-22 18:18:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
#ifdef CKISEKI
#include <experimental/iterator>
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
void debug_(auto s, auto ...a) {
cerr << "\e[1;32m(" << s << ") = (";
int f = 0;
(..., (cerr << (f++ ? ", " : "") << a));
cerr << ")\e[0m\n";
}
void orange_(auto s, auto L, auto R) {
cerr << "\e[1;33m[ " << s << " ] = [ ";
using namespace experimental;
copy(L, R, make_ostream_joiner(cerr, ", "));
cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif
int enc(string s) {
int r = 0;
for (auto c : s)
r = r * 128 + c;
return r;
}
string dec(int x) {
string s(1, x % 128);
if (x > 128)
s = char(x / 128) + s;
return s;
}
bool used[128];
int hc[128];
int cnt[128 * 128];
vector<int> same[1000];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
memset(used, 0, sizeof(used));
memset(hc, 0, sizeof(hc));
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i < 1000; ++i)
same[i].clear();
int n;
cin >> n;
vector<string> a(n * n);
for (auto &ai : a)
cin >> ai;
string ans(n, '?');
for (auto ai : a)
cnt[enc(ai)]++;
for (int i = 0; i < 128; ++i) {
if (cnt[i] == 2 * n - 1)
ans[0] = dec(i)[0];
}
for (auto &ai : a)
if (ai.size() == 1)
ai = ans[0] + ai;
vector<int> tot(n);
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
tot[(i * j) / n]++;
for (int i = 0; i < n; ++i) {
same[tot[i]].push_back(i);
}
for (auto ai : a)
hc[int(ai[0])]++;
auto dfs = [&](auto self, int i) -> bool {
if (i == 128)
return true;
if (hc[i] == 0)
return self(self, i + 1);
for (int x : same[hc[i]]) {
// x is i
if (used[x])
continue;
used[x] = true;
ans[x] = i;
if (self(self, i + 1))
return true;
ans[x] = '?';
used[x] = false;
}
return false;
};
assert (dfs(dfs, 0));
set<char> s;
for (int i = 0; i < n; ++i) {
if (i < 26)
s.insert(i + 'a');
else
s.insert(i - 26 + 'A');
}
for (auto x : ans) {
s.erase(x);
}
ans.back() = *s.begin();
cout << ans << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3924kb
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: 3684kb
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: 3ms
memory: 3760kb
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 fcehabgd bhgfedcia jhcfgideba fjbadkegcih klhgjbaedcif igkjmclfedhba nfliajhgmbdcek anmflijbgkhdceo nofmljkchdbegipa aponblgjihcfqdkme iqmonhckfrpgjedlba prisdombkjqghfencla tcrdpoaklmjihfgeqsbn utiraponmlgskhjfecdbq qotsrvjnumlipkegfhdcba pvutsrhwoimlkjnqgfedbca xbvuts...
result:
wrong answer The product 2*5=10 is not in the output at case #6