SHARE
TWEET

I. Экзаменационные билеты

a guest Oct 12th, 2017 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <math.h>
  4. #include <algorithm>
  5. #include <string>
  6. #include <string.h>
  7. #include <set>
  8. using namespace std;
  9.  
  10. const int INF = 1000000007;
  11. const int mod = 1000000007;
  12.  
  13. int n;
  14. long long ar[2010];
  15. long long res;
  16. long long suffix_sum[2010];
  17.  
  18. int main(){
  19. //  freopen("input.txt", "r", stdin);
  20. //  freopen("output.txt", "w", stdout);
  21.   cin >> n;
  22.   for (int i = 0; i < n; ++i) {
  23.     cin >> ar[i];
  24.   }
  25.  
  26.   suffix_sum[n - 1] = ar[n - 1];
  27.   for (int i = n - 2; i >= 0; --i) {
  28.     suffix_sum[i] = suffix_sum[i + 1] + ar[i];
  29.   }
  30.  
  31.   for (int i = 0; i < n - 2; ++i) {
  32.     for (int j = i + 1; j < n - 1; ++j) {
  33.       res += ar[i] * ar[j] * suffix_sum[j + 1];
  34.       res %= mod;
  35.     }
  36.   }
  37.   cout << res;
  38.   return 0;
  39. }
RAW Paste Data
Top