fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <set>
  5. #include <algorithm>
  6. #include <map>
  7.  
  8. using namespace std;
  9.  
  10. const int stalin = 1000000000 + 7;
  11.  
  12. int main() {
  13. ios_base::sync_with_stdio(0);
  14. cin.tie(0);
  15. cout.tie(0);
  16.  
  17. int n;
  18. cin >> n;
  19. vector <int> dziury(n + 1);
  20. long long il = 1;
  21.  
  22. for (int i = 1; i <= n; i++) {
  23. cin >> dziury[i];
  24. }
  25.  
  26. sort(dziury.begin(), dziury.end());
  27.  
  28. int k = 0, q = 0;
  29.  
  30. for (int i = n; i > 0; i--) {
  31. while (n - k > 0 && i <= dziury[n - k]) {
  32. k++;
  33. }
  34. il *= k - q;
  35. il %= stalin;
  36. q++;
  37. }
  38.  
  39. cout << il;
  40. }
Success #stdin #stdout 0.01s 5284KB
stdin
4
1 3 4 4
stdout
4