QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#684744 | #7882. Linguistics Puzzle | Doubeecat | WA | 4ms | 3852kb | C++20 | 2.7kb | 2024-10-28 15:32:02 | 2024-10-28 15:32:02 |
Judging History
answer
/*
Undo the destiny.
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
const int N = 55;
const int M = 55 * 55;
int n;
int cnt1[N],cnt2[N][N],num[M],ans[N];
bool vis[N];
int getnum(char now) {
if (now <= 'z' && now >= 'a') return now - 'a';
else return now - 'A' + 26;
}
char getans(int now) {
if (now < 26) return now + 'a';
else return now - 26 + 'A';
}
bool dfs(int dep) {
if (dep >= n) {
return 1;
}
//dep是数字,现在枚举一个出现次数相同的字符找
//i 是字符
bool hav = 0;
for (int i = 0;i < n;++i) {
if (vis[i]) continue;
if (cnt1[i] == num[dep]) {
bool flag = 1;
for (int j = 0;j < dep;++j) {
if ((cnt2[ans[j]][i] != num[j * n + dep] && j) && (cnt2[i][ans[j]] != num[dep * n + j] && dep)) {
//cout << "errL"<<dep << " " << i << " " << ans[j] << "\n" << cnt2[ans[j]][i] << " " << num[ans[j]*n+i]<<" " << cnt2[i][ans[j]] << " " << num[i * n + ans[j]]<< "\n";
flag = 0;
}
}
//cout << dep << " " << i << " " << flag << "\n";
if (flag) {
ans[dep] = i;
vis[i] = 1;
if (!dfs(dep+1)) vis[i] = 0,ans[dep] = 0;
else hav = 1;
}
}
}
return hav;
}
void solve() {
cin >> n;
memset(num,0,sizeof num);
memset(cnt1,0,sizeof cnt1);
memset(cnt2,0,sizeof cnt2);
memset(ans,0,sizeof ans);
memset(vis,0,sizeof vis);
for (int i = 0;i < n;++i) {
for (int j = 0;j < n;++j) {
num[i*j]++;
}
}
//cout << "num:";
//for (int i = 0;i < n*n;++i) cout << num[i] << " ";
//cout <<"\n";
for (int i = 0;i < n;++i) {
for (int j = 0;j < n;++j) {
string now;cin >> now;
if (now.size() == 1) cnt1[getnum(now[0])]++;
else cnt2[getnum(now[0])][getnum(now[1])]++;
}
}
/*for (int i = 0;i < n;++i) {
for (int j = 0;j < n;++j) {
cout << cnt2[i][j] << " ";
}
cout << "\n";
}
cout << "cnt1:";
for (int i = 0;i < n;++i) cout << cnt1[i] << " ";
cout << "\n";*/
dfs(0);
for (int i = 0;i < n;++i) cout << getans(ans[i]);
cout << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);//cout.tie(0);
int T;cin >> T;
while (T--) solve();
return 0;
}
/*
1
4
d d d d d c b a d b cd cb d a cb bc
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3640kb
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: 3640kb
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: 4ms
memory: 3852kb
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 fcbeahgd bhgfedcia jhcgfideba fjbadkegcih klhgjbaedcif igkjmclfedhba nflijahgmbdcek anmlfijbgkhdceo nofmlkjchdbegipa aponblgjihcfqdkme iqmonhckfrpgjedlba prisodmbkjqghfencla tcrdpoaklmjihfgeqsbn utiraponmlksghjfecdbq qotsrvjunmlkpiegfhdcba pvutsrhwoimlkjnqgfedbac xbvuts...
result:
wrong answer The product 2*5=10 is not in the output at case #6