QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#755915 | #7882. Linguistics Puzzle | tkt0506 | WA | 2ms | 3836kb | C++14 | 1.6kb | 2024-11-16 18:23:23 | 2024-11-16 18:23:24 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 52;
int c1[N], c2[N][N], cnt[N*N], ans[N];
bool vis[N];
bool f2 = 0;
void precompute(int n){
memset(cnt, 0, sizeof cnt);
memset(c1, 0, sizeof c1);
memset(c2, 0, sizeof c2);
memset(vis, 0, sizeof vis);
for(int i=0; i<n; i++)for(int j=0; j<n; j++)cnt[i*j]++;
f2 = 0;
}
void dfs(int u, int n){
if(u >= n){
f2 = 1;
return ;
}
for(int i=0; i<n; i++){ // match char u -> int i
if(vis[i])continue; // int used
vis[i] = 1;
if(cnt[i] == c1[u]){
bool f = 1;
for(int j=0; j<u; j++){
// char j : int ans[j]
// char u : int i
if(ans[j] && c2[j][u] != cnt[ans[j]*n+i])f = 0;
if(i && c2[u][j] != cnt[i*n+ans[j]])f = 0;
}
if(f){
// cout << "char: " << u << " <-> int: " << i << "\n";
ans[u] = i;
dfs(u+1,n);
if(f2)break;
}
}
vis[i] = 0;
}
}
void solve(){
int n;
cin >> n;
precompute(n);
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
string s;
cin >> s;
if(s.length() == 1) c1[s[0]-'a']++;
else c2[s[0]-'a'][s[1]-'a']++;
}
}
dfs(0, n);
vector<char>a2(n);
for(int i=0; i<n; i++)a2[ans[i]] = (char)(i+'a');
for(char c : a2)cout << c;
cout << "\n";
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while(t--)solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3836kb
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: 3800kb
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: 2ms
memory: 3620kb
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 { at case #25