Advertisement
7oSkaaa

Untitled

Apr 26th, 2022
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.09 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define cin_2d(vec, n, m) for(int i = 0; i < n; i++) for(int j = 0; j < m && cin >> vec[i][j]; j++);
  6. #define cout_2d(vec, n, m) for(int i = 0; i < n; i++, cout << "\n") for(int j = 0; j < m && cout << vec[i][j] << " "; j++);
  7. #define cout_map(mp) for(auto& [f, s] : mp) cout << f << "  " << s << "\n";
  8. #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n";
  9. #define fixed(n) fixed << setprecision(n)
  10. #define ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  11. #define fill(vec, value) memset(vec, value, sizeof(vec));
  12. #define Num_of_Digits(n) ((int)log10(n) + 1)
  13. #define mod_combine(a, b, m) (((a % m) * (b % m)) % m)
  14. #define all(vec) vec.begin(), vec.end()
  15. #define rall(vec) vec.rbegin(), vec.rend()
  16. #define sz(x) int(x.size())
  17. #define debug(x) cout << #x << ": " << (x) << "\n";
  18. #define fi first
  19. #define se second
  20. #define Pair pair < int, int >
  21. #define ll long long
  22. #define ull unsigned long long
  23. #define Mod  1'000'000'007
  24. #define OO 2'000'000'000
  25. #define EPS 1e-9
  26. #define PI acos(-1)
  27.  
  28. template < typename T = int > istream& operator >> (istream &in, vector < T > &v) {
  29.     for (auto &x: v) in >> x;
  30.     return in;
  31. }
  32.  
  33. template < typename T = int > ostream& operator << (ostream &out, const vector < T > &v) {
  34.     for (const T &x: v) out << x << ' ';
  35.     return out;
  36. }
  37.  
  38. void AhMeD_HoSSaM(){
  39.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  40.     #ifndef ONLINE_JUDGE
  41.         freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  42.     #endif
  43. }
  44.  
  45. void Solve(){
  46.     string s;
  47.     int sz, x;
  48.     cin >> s >> sz >> x;
  49.     map < char, int > occ;
  50.     vector < char > chars;
  51.     for(char c = 'A'; c <= 'Z'; c++) occ[c] = 0, chars.push_back(c);
  52.     for(char c = 'a'; c <= 'z'; c++) occ[c] = 0, chars.push_back(c);
  53.     for(auto& c : s) occ[c]++;
  54.     int max_score = 0;
  55.     string best_answer;
  56.     for(int i = 0; i < sz(chars); i++){
  57.         int score = 0, j = i;
  58.         if(occ[chars[i]] == 0) continue;
  59.         while(score < x && j < sz(chars)){
  60.             if(occ[chars[j]] == 0){
  61.                 j++;
  62.                 continue;
  63.             }
  64.             score = j - i;
  65.             int idx = i;
  66.             string ans;
  67.             while(idx < j){
  68.                 ans += string(min(occ[chars[idx]], sz - sz(ans)), chars[idx]);
  69.                 idx++;
  70.             }
  71.             if(sz(ans) == sz) ans.pop_back();
  72.             for(int ii = 0; ii < occ[chars[j]] && sz(ans) < sz; ii++) ans += chars[j];
  73.             cout << score << ' ' << ans << '\n';
  74.             if(max_score < score && sz(ans) == sz && score < x)
  75.                 max_score = score, best_answer = ans;
  76.             else if (max_score == score && sz(ans) == sz && score < x)
  77.                 max_score = score, best_answer = min(best_answer, ans);
  78.             j++;
  79.         }
  80.     }
  81.     if(best_answer.empty()) cout << "Ammit wins\n";
  82.     else cout << "Taweret wins : " << best_answer << '\n';
  83. }
  84.  
  85. int main(){
  86.     AhMeD_HoSSaM();
  87.     int t = 1;
  88.     cin >> t;
  89.     while(t--)
  90.         Solve();
  91.     return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement