yeputons

Untitled

Apr 12th, 2014
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include <cstdio>
  2. #include <ctime>
  3. #include <cstdlib>
  4. #include <algorithm>
  5. #include <iostream>
  6. #include <chrono>
  7. #include <vector>
  8.  
  9. using namespace std;
  10. using namespace chrono;
  11.  
  12. typedef vector<int> vi;
  13. typedef vector<vi> vvi;
  14.  
  15. const int n = 1000;
  16. //int d[n][n];
  17. unsigned calc(int start) {
  18.   unsigned cur = start;
  19.   vvi d(n, vi(n));
  20.   for (int i = 0; i < n; i++)
  21.   for (int j = 0; j < n; j++) {
  22.     d[i][j] = cur;
  23.     cur = cur * 54328568 + 7384;
  24.   }
  25.  
  26.   for (int i = 0; i < n; i++)
  27.   for (int j = 0; j < n; j++)
  28.   for (int k = 0; k < n; k++)
  29.     d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
  30.   unsigned res = 0;
  31.   for (int i = 0; i < n; i++)
  32.   for (int j = 0; j < n; j++) {
  33.     res += d[i][j];
  34.   }
  35.   return res;
  36. }
  37.  
  38. int main() {
  39.   auto start = steady_clock::now();
  40.  
  41.   unsigned sum = 0;
  42.   #pragma omp parallel for
  43. //  #pragma omp parallel for num_threads(1)
  44.   for (int i = 0; i < 4; i++)
  45.     sum += calc(i);
  46.   printf("%d\n", sum);
  47.   printf("%d\n", clock());
  48.   cout << duration_cast<microseconds>(steady_clock::now() - start).count() << endl;
  49.   return 0;
  50. }
Add Comment
Please, Sign In to add comment