Codeforces Round 921 (Div. 2) 1925C. Did We Get Everything Covered? Solution



 Problem Link :  https://codeforces.com/contest/1925/problem/C 

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t;
  8. cin >> t;
  9. while (t--) {
  10. int n , k , m ; cin >> n >> k >> m ;
  11. string s ; cin >> s ;
  12. string ans ="";
  13. set<char>st ;
  14. for (int i = 0 ; i < m ; i++){
  15. st.insert(s[i]) ;
  16. if(st.size() == k ){
  17. ans +=s[i] ;
  18. st.clear() ;
  19. }
  20. }
  21. if(ans.size() >= n){
  22. cout <<"YES\n";
  23. }
  24. else{
  25. cout <<"NO\n" ;
  26. char mis_ch ;
  27. for( int i = 0 ; i < k ; i++){
  28. char c = (char)('a'+i) ;
  29. if(st.count(c) == 0){
  30. mis_ch = c ;
  31. break ;
  32. }
  33. }
  34. while(ans.size() < n) {
  35. ans += mis_ch ;
  36. }
  37. cout << ans <<'\n';
  38. }
  39. }
  40. return 0 ;
  41. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.