比赛 EYOI与SBOI开学欢乐赛4th 评测结果 WWWTW
题目名称 Cafe Stella 最终得分 0
用户昵称 lihaoze 运行时间 1.272 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2022-09-12 21:20:08
显示代码纯文本
#include <bits/stdc++.h> 
 
const int N = 11;
int n;
std::string s[N][N];
std::map<char, int> mp;
bool st[N];
 
bool valid(int base) {
	for (int i = 1; i <= n; ++ i) 
		for (int j = 1; j <= n; ++ j) {
			if (i == 1 && j == 1) break;
			if (s[i][j].size() == 2) {
				if (mp[s[i][1][0]] + mp[s[1][j][0]] != mp[s[i][j][0]] * base + mp[s[i][j][1]]) return false;
			} else {
				if (mp[s[i][1][0]] + mp[s[1][j][0]] != mp[s[i][j][0]]) return false;
			}
		}
	return true;
}
 
void dfs(int now) {
	if (now == n + 1) {
		for (int i = 1; i <= 10; ++ i) 
			if (valid(i)) {
				for (int j = 2; j <= n; ++ j) 
					std::cout << s[j][1][0] << '=' << mp[s[j][1][0]] << ' ';
				std::cout << '\n' << i;
			}
		return;
	}
	for (int i = 0; i < 10; ++ i) 
		if (!st[i]) {
			mp[s[now][1][0]] = i;
			st[i] = true;
			dfs(now + 1);
			st[i] = false;
		}
}
 
int main() {
	freopen("murasame_adultxp3.in", "r", stdin);
	freopen("murasame_adultxp3.out", "w", stdout);
	std::cin >> n;
	for (int i = 1; i <= n; ++ i)
		for (int j = 1; j <= n; ++ j)
			std::cin >> s[i][j];
	dfs(2);
	return 0;
}