QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#537731 | #7882. Linguistics Puzzle | BrotherCall | WA | 11ms | 3892kb | C++20 | 3.0kb | 2024-08-30 17:50:43 | 2024-08-30 17:50:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 3000;
int t , n;
string guai = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
int GS[N] , QD[N] , JB[N];
int gs[N] , qd[N] , jb[N];
int ans[N];
string s;
string sss;
string ssss;
string yl[N] , hl[N];
int ch[N] , seat[N];
void cs(int x,int n) {
if(x / n != 0) cs(x / n , n);
sss += guai[x % n];
}
void css(int x,int n) {
if(x / n != 0) cs(x / n , n);
ssss += guai[ans[x % n]];
}
bool compare(int s1,int s2) {
return gs[s1] > gs[s2];
}
bool check() {
int cnt = 0;
for(int i = 0;i <= n - 1;i ++)
for(int j = 0;j <= n - 1;j ++) {
int now = i * j;
ssss = "";
css(now , n);
cnt ++;
hl[cnt] = ssss;
}
sort(hl + 1 , hl + 1 + n * n);
for(int i = 1;i <= n * n;i ++)
if(hl[i] != yl[i]) return false;
return true;
}
bool vis[N];
void dfs(int x,int zfgs) {
if (x == zfgs + 1) {
if (check()) {
for(int i = 0;i <= n - 1;i ++)
cout << guai[ans[i]];
cout << "\n";
}
return ;
}
for (int i = 1; i <= zfgs; i++) {
if (!vis[i]) {
vis[i] = true;
ans[seat[x]] = ch[i];
dfs(x + 1 , zfgs);
vis[i] = false;
}
}
}
void solve() {
cin >> n;
for(int i = 0;i <= 200;i ++)
gs[i] = 0 , qd[i] = 0 , GS[i] = QD[i] = 0 , jb[i] = JB[i] = 0;
for(int i = 0;i <= n - 1;i ++)
for(int j = 0;j <= n - 1;j ++) {
sss = "";
cs(i * j , n);
if(sss.size() == 2) GS[sss[0]] ++ , JB[sss[1]] ++;
if(sss.size() == 1) QD[sss[0]] ++;
}
for(int i = 1;i <= n * n;i ++) {
cin >> s;
yl[i] = s;
if(s.size() == 2) gs[s[0]] ++ , jb[s[1]] ++;
if(s.size() == 1) qd[s[0]] ++;
}
sort(yl + 1 , yl + 1 + n * n);
for(int i = 0;i <= n - 1;i ++)
ans[i] = -1;
int zfgs = 0 , wzgs = 0;
for(int i = 0;i <= n - 1;i ++) {
int wocao = 0;
int num = 0;
for(int j = 0;j <= n - 1;j ++) {
if(gs[guai[j]] == GS[guai[i]] && qd[guai[j]] == QD[guai[i]] && jb[guai[j]] == JB[guai[i]]) {
wocao ++;
num = j;
}
}
if(wocao == 1) ans[i] = num;
else seat[++wzgs] = i;
}
for(int i = 0;i <= n - 1;i ++) {
bool flag = 0;
for(int j = 0;j <= n - 1;j ++) {
if(ans[j] == -1) continue;
if(i == ans[j]) {
flag = 1;
break;
}
}
if(flag == 0) ch[++zfgs] = i;
}
if(wzgs == 0) {
for(int i = 0;i <= n - 1;i ++)
cout << guai[ans[i]];
cout << "\n";
} else {
dfs(1 , zfgs);
}
}
int main() {
cin >> t;
while(t --) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3772kb
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: 1ms
memory: 3760kb
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: 11ms
memory: 3892kb
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 length at case #28