记录编号 575381 评测结果 AAAAA
题目名称 Cafe Stella 最终得分 100
用户昵称 Gravatarlihaoze 是否通过 通过
代码语言 C++ 运行时间 0.008 s
提交时间 2022-09-12 22:34:30 内存使用 0.00 MiB
显示代码纯文本
#include <bits/stdc++.h> 
 
const int N = 11;
int n;
std::string s[N][N];
std::map<char, int> mp;
bool st[N], flag;
 
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) && !flag) {
                flag = true;
                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 < n; ++ 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);
    if (!flag) std::cout << "FccKcuf";
    return 0;
}