Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- by: senb1
- */
- #include <bits/stdc++.h>
- #define ll long long
- #define all(x) x.begin(), x.end()
- #define fr first
- #define sc second
- #define mk make_pair
- using namespace std;
- const ll inf = 1e9 + 6;
- vector<string> nums = {
- "BIR", "eKI", "uc", "ToRT", "BES",
- "ALTY", "JETI", "SEGIZ", "TOGUZ", "ON"}; // * all possible numbers
- bool checkForCorrectEncryption(string encrypted, string original) {
- map<char, char> mp2;
- map<char, char> mp;
- for (int i = 0; i < original.size(); i++) {
- if ((int)mp2[original[i]] == 0 && (int)mp[encrypted[i]] == 0) {
- mp2[original[i]] = encrypted[i];
- mp[encrypted[i]] = original[i];
- } else if (mp2[original[i]] != encrypted[i] ||
- mp[encrypted[i]] != original[i])
- return false;
- }
- return true;
- }
- void solve() {
- string s, s3;
- cin >> s;
- ll n = s.size(), ans = inf;
- for (ll i = 0; i < 10; i++) {
- for (ll j = 0; j < 10; j++) {
- for (ll k = 0; k < 10; k++) { // * check all possible combinations
- string s2 = nums[i] + nums[j] + nums[k];
- if (s2.size() == n) {
- if (checkForCorrectEncryption(s, s2)) {
- ans = min(ans, i + j + k + 3);
- // cout<<s2<<endl;
- }
- }
- }
- }
- }
- if (ans == inf) // ! if ans is inf then s is invalid
- cout << 1 << endl;
- else // * otherwise s is valid
- cout << ans << endl;
- }
- /*
- ONONON
- 9
- VSZVFKZTWK
- 7
- PSPSPS
- 9
- FKZTWVVVSZS
- 1
- */
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- int t = 1;
- // cin >> t;
- while (t--)
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement