QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#537730 | #7882. Linguistics Puzzle | BrotherCall | WA | 1ms | 3808kb | C++20 | 3.0kb | 2024-08-30 17:50:29 | 2024-08-30 17:50:29 |
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() {
freopen("fuck.txt","r",stdin);
cin >> t;
while(t --) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3808kb
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:
result:
wrong output format Unexpected end of file - token expected