Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <string>
- #include <algorithm>
- using namespace std;
- long long n, a[100], used[100], x[100];
- string s[100];
- bool check() {
- for (long long i = 1; i <= n; i++) {
- x[i] = 0;
- if (a[s[i][0] - 'a'] == 0 && s[i].size() > 1)
- return false;
- for (long long j = 0; j < s[i].length(); j++)
- x[i] = x[i] * 10 + a[s[i][j] - 'a'];
- if (i >= 2 && x[i] <= x[i - 1])
- return false;
- }
- return true;
- }
- void rec(long long v) {
- if (v > 9) {
- if (check()) {
- cout << "Yes" << endl;
- for (long long i = 0; i <= 9; i++)
- cout << a[i] << ' ';
- exit(0);
- }
- return;
- }
- for (long long i = 0; i < 10; i++) {
- if (!used[i]) {
- a[v] = i;
- used[i] = 1;
- rec(v + 1);
- used[i] = 0;
- }
- }
- }
- int main() {
- freopen("tiv.in", "r", stdin);
- freopen("tiv.out", "w", stdout);
- cin >> n;
- for (long long i = 1; i <= n; i++)
- cin >> s[i];
- rec(0);
- cout << "No";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment