Codeforces Round #847 (Div. 3) 1790D. Matryoshkas Solution



 Problem Link : https://codeforces.com/contest/1790/problem/D

Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmanir-Rahim******///
  3. /// Abul Hasnat Tonmoy
  4. /// Department of CSE,23rd batch
  5. /// Islamic University,Bangladesh
  6. ///**********ALLAH IS ALMIGHTY************///
  7. #include <bits/stdc++.h>
  8. using namespace std ;
  9. int32_t main() {
  10. ios_base::sync_with_stdio(0);
  11. cin.tie(0);
  12. int t ;
  13. cin >> t ;
  14. while ( t-- ){
  15. int n ;
  16. cin >> n ;
  17. int a [n+1] ;
  18. map < int , int > mp ;
  19. for ( int i = 1 ; i <= n ; i++ ){
  20. cin >> a[i] ;
  21. mp[a[i]]++ ;
  22. }
  23. int ans = 0 ;
  24. sort( a + 1 , a + n + 1 ) ;
  25. for ( int i = 1 ; i <= n ; i++ ){
  26. int v = a [i] ;
  27. if ( mp[v] > 0 ){
  28. ans++;
  29. while ( mp[v] > 0 ) {
  30. mp[v]--;
  31. v++;
  32. }
  33. }
  34. }
  35. cout << ans << endl;
  36. }
  37. return 0 ;
  38. }

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.