fork(7) download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. const int maxN = 100000;
  6. // bool u[maxN];
  7. int a[maxN];
  8. int b[maxN];
  9. int main() {
  10. int N;
  11. cin >> N;
  12. vector<bool> u(N);
  13. long long total = 0;
  14. for (int i = 0; i < N; ++i) {
  15. a[i] = rand() % N;
  16. b[i] = rand() % N;
  17. }
  18. for (int it = 0; it < N; ++it) {
  19. for (int i = 0; i < N; ++i) {
  20. int x = a[i];
  21. u[x] = 1;
  22. }
  23. for (int i = 0; i < N; ++i) {
  24. int x = b[i];
  25. u[x] = 0;
  26. }
  27. for (int i = 0; i < N; ++i) {
  28. total += u[i];
  29. u[i] = 0;
  30. }
  31. }
  32. cout << total / N << endl;
  33. return 0;
  34. }
Success #stdin #stdout 0.45s 4556KB
stdin
10000
stdout
2369