Advertisement
senb1

krsu 3364

Feb 21st, 2023
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. /*
  2. by: senb1
  3. */
  4. #include <bits/stdc++.h>
  5.  
  6. #define ll long long
  7. #define all(x) x.begin(), x.end()
  8. #define fr first
  9. #define sc second
  10. #define mk make_pair
  11.  
  12. using namespace std;
  13.  
  14. const ll inf = 1e9 + 6;
  15.  
  16. vector<string> nums = {
  17.     "BIR",  "eKI",  "uc",    "ToRT",  "BES",
  18.     "ALTY", "JETI", "SEGIZ", "TOGUZ", "ON"}; // * all possible numbers
  19.  
  20. bool checkForCorrectEncryption(string encrypted, string original) {
  21.     map<char, char> mp2;
  22.     map<char, char> mp;
  23.     for (int i = 0; i < original.size(); i++) {
  24.         if ((int)mp2[original[i]] == 0 && (int)mp[encrypted[i]] == 0) {
  25.             mp2[original[i]] = encrypted[i];
  26.             mp[encrypted[i]] = original[i];
  27.         } else if (mp2[original[i]] != encrypted[i] ||
  28.                    mp[encrypted[i]] != original[i])
  29.             return false;
  30.     }
  31.  
  32.     return true;
  33. }
  34.  
  35. void solve() {
  36.     string s, s3;
  37.     cin >> s;
  38.     ll n = s.size(), ans = inf;
  39.     for (ll i = 0; i < 10; i++) {
  40.         for (ll j = 0; j < 10; j++) {
  41.             for (ll k = 0; k < 10; k++) { // * check all possible combinations
  42.                 string s2 = nums[i] + nums[j] + nums[k];
  43.                 if (s2.size() == n) {
  44.                     if (checkForCorrectEncryption(s, s2)) {
  45.                         ans = min(ans, i + j + k + 3);
  46.                         // cout<<s2<<endl;
  47.                     }
  48.                 }
  49.             }
  50.         }
  51.     }
  52.  
  53.     if (ans == inf) // ! if ans is inf then s is invalid
  54.         cout << 1 << endl;
  55.     else // * otherwise s is valid
  56.         cout << ans << endl;
  57. }
  58. /*
  59. ONONON
  60. 9
  61. VSZVFKZTWK
  62. 7
  63. PSPSPS
  64. 9
  65. FKZTWVVVSZS
  66. 1
  67. */
  68.  
  69. int main() {
  70.     ios::sync_with_stdio(0);
  71.     cin.tie(0);
  72.  
  73.     int t = 1;
  74.     // cin >> t;
  75.     while (t--)
  76.         solve();
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement