QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#646178#7882. Linguistics Puzzlebessie_goes_mooTL 0ms0kbC++143.0kb2024-10-16 21:34:392024-10-16 21:34:40

Judging History

你现在查看的是最新测评结果

  • [2024-10-16 21:34:40]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-10-16 21:34:39]
  • 提交

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], tong1[101][101], tong2[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;
			tong1[i][j] = 0;
			tong2[i][j] = 0;
		}
	}
}
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() {
	freopen("out.txt", "r", stdin);
	T = read();
	for (int yyc = 1; yyc <= T; yyc++) {
		n = read();
		clear();
		int maxx = 2;
		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]);
			}
			if (l == 2) {
				tong1[x[i][0]][x[i][1]]++;
			}
		}
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				dui[++cnt] = i * j;
				if (i * j >= n) {
					tong2[dui[cnt] % n][dui[cnt] / n]++;
				}
			}
		}
		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;
					}
				}
			}
		}
		int numm = 0, wei = 0;
		for (int i = 0; i < n; i++) {
			numm = 0, wei = 0;
			for (int j = 0; j < n; j++) {
				numm += tong[i][j];
				if(tong[i][j]==1)
					wei=j;
			}
			if (numm == 1) {
				for (int j = 0; j < n; j++) {
					for (int k = 0; k < n; k++) {
						if (tong2[i][j] != tong1[wei][k])
							tong[j][k] = 0;
					}
				}
			}
		}
		Maxmatch();
		for (int i = 0; i < n; i++) {
			cout << zhuan(con_x[i]);
		}
		cout << endl;
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

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: