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 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.