QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#645960 | #7882. Linguistics Puzzle | bessie_goes_moo | WA | 16ms | 6976kb | C++14 | 2.5kb | 2024-10-16 20:38:51 | 2024-10-16 20:38:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 5;
int T, n, maxx;
int num1[101], num2[101], dui[N], tong[101][101];
inline int read() {
int al = 0, fh = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
fh = -1;
ch = getchar();
}
while (ch <= '9' && ch >= '0') {
al = al * 10 + ch - '0';
ch = getchar();
}
return al * fh;
}
char str[101];
vector<int> x[N];
void clear() {
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
tong[i][j] = 1;
}
}
}
int chu(int a) {
if (a <= 'z' && a >= 'a') {
return a - 'a';
}
else {
return a - 'A' + 26;
}
}
int con_x[101], con_y[101], vis[101];
bool dfs(int x) {
for (int y = 0; y < n; y++)
if (tong[x][y] && !vis[y]) {
vis[y] = true;
if (con_y[y] == -1 || dfs(con_y[y])) {
con_x[x] = y;
con_y[y] = x;
return true;
}
}
return false;
}
void Maxmatch() {
for (int i = 0; i <= n; i++) {
con_y[i] = con_x[i] = -1;
}
for (int i = 0; i < n; i++)
{
{
memset(vis, false, sizeof(vis));
dfs(i);
}
}
}
char zhuan(int x) {
if (x <= 25)
return x + 'a';
else return x + 'A' - 26;
}
signed main() {
T = read();
for (int yyc = 1; yyc <= T; yyc++) {
n = read();
clear();
int maxx=101;
for (int i = 1; i <= n * n; i++) {
scanf("%s", str);
int l = strlen(str);
maxx = max(maxx, l);
x[i].resize(l);
for (int j = 0; j < l; j++) {
x[i][j] = chu(str[l - 1 - j]);
}
}
int cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
dui[++cnt] = i * j;
}
}
for (int i = 0; i < maxx; i++) {
for (int j = 0; j <= n; j++) {
num1[j] = 0;
num2[j] = 0;
}
for (int j = 1; j <= n * n; j++) {
if (x[j].size() >= i + 1) {
num2[x[j][i]]++;
}
}
for (int j = 1; j <= cnt; j++) {
if (dui[j] != -1) {
num1[dui[j] % n]++;
if(dui[j]/n==0)
dui[j]=-1;
else dui[j] /= n;
}
}
// cout<<i<<":";
// for(int j=0;j<n;j++){
// cout<<num1[j]<<" "<<num2[j]<<endl;
// }
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
if (num1[j] == num2[k]) {
}
else {
tong[j][k] = 0;
}
}
}
}
// for(int i=0;i<n;i++){
// for(int j=0;j<n;j++){
// cout<<tong[i][j]<<" ";
// }
// cout<<endl;
// }
Maxmatch();
for (int i = 0; i < n; i++) {
cout << zhuan(con_x[i]);
}
cout << endl;
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 6976kb
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: 6784kb
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: 16ms
memory: 6776kb
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 pvutsrhwoimlnjkqgfedbca xbvuts...
result:
wrong answer The product 3*20=60 is not in the output at case #21