fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. using namespace std;
  6. #define all(v) (v.begin()), (v.end())
  7.  
  8. void fast_io()
  9. {
  10. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  11. }
  12.  
  13. bool check_digits(int val, int k){
  14. int sum = 0;
  15. bool zero = false;
  16. while (val > 0){
  17. if (val%10 > k)
  18. return false;
  19. if (val%10 == 0)
  20. zero = true;
  21. sum += val%10;
  22. val /= 10;
  23. }
  24. if (sum == k*(k+1)/2 && zero)
  25. return true;
  26. else
  27. return false;
  28. }
  29.  
  30. int main()
  31. {
  32. fast_io();
  33. int n, k;
  34. cin >> n >> k;
  35.  
  36. int counter = 0;
  37. for (int i = 0; i < n; i++){
  38. int val=0;
  39. cin >> val;
  40. if (k == 0 && val == 0)
  41. counter++;
  42. if (check_digits(val,k) && k > 0)
  43. counter++;
  44. }
  45. cout << counter << endl;
  46. }
Success #stdin #stdout 0.01s 5280KB
stdin
2 1
1
10
stdout
1