Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #pragma comment(linker, "/stack:200000000")
  4. #pragma GCC optimize("Ofast")
  5. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  6. #pragma GCC optimize("unroll-loops")
  7. #pragma GCC optimize("O3")
  8.  
  9. #define F first
  10. #define S second
  11. #define pb push_back
  12. #define llong long long
  13. #define int llong
  14. #define ld long double
  15. #define endl '\n'
  16.  
  17. #ifdef BUCKY_IS_ALIVE
  18. #define cerr if(0) cerr
  19. #else
  20. #endif // BUCKY_IS_ALIVE
  21.  
  22. using namespace std;
  23.  
  24. const int N = 1e5 + 5;
  25. const int M = 1e5 + 5;
  26. const int B = 2100;
  27. const int sum = 2e9;
  28. const int MOD = 1e9 + 7;
  29. const int MOD1 = 1e9 + 7;
  30. const int rx[4] = {0, 1, -1, 0};
  31. const int ry[4] = {1, 0, 0, -1};
  32. const char rr[5]= {'5', 'N', 'E', 'S', 'W'};
  33.  
  34.  
  35.  
  36. main() {
  37. ios_base::sync_with_stdio(0);
  38. cin.tie(0);
  39. cout.tie(0);
  40. srand(time(0));
  41. #ifdef BUCKY_IS_ALIVE
  42. freopen("input.txt", "r", stdin);
  43. freopen("output.txt", "w", stdout);
  44. #endif
  45.  
  46. int n;
  47. cin >> n;
  48. vector <pair <int, int> > all;
  49. for(int i = 0; i < n; i++) {
  50. int x;
  51. cin >> x;
  52. all.pb({x, i});
  53. }
  54.  
  55. sort(all.begin(), all.end());
  56. int cur = all[1].F - all[0].F;
  57. for(int i = 1; i < n; i++) {
  58. if (all[i].F - all[i - 1].F == cur)
  59. continue;
  60. else {
  61. vector <int> a;
  62. for(int j = 0; j < n; j++) {
  63. if (i == j)
  64. continue;
  65. a.pb(all[j].F);
  66. }
  67.  
  68. bool ok = 1;
  69.  
  70. for(int j = 1; j < a.size(); j++) {
  71. if (a[j] - a[j - 1] == cur)
  72. continue;
  73. ok = 0;
  74. break;
  75. }
  76.  
  77. if (ok) {
  78. cout << all[i].S + 1 << endl;
  79. return 0;
  80. }
  81. break;
  82.  
  83. }
  84. }
  85.  
  86. if (all.size() == 2) {
  87. cout << all[0].S + 1 ;
  88. return 0;
  89. }
  90.  
  91. int nom = all[0].S;
  92. reverse(all.begin(), all.end());
  93. all.pop_back();
  94. reverse(all.begin(), all.end());
  95.  
  96. bool ok = 1;
  97.  
  98. cur = all[1].F - all[0].F;
  99. for(int i = 1; i < all.size(); i++) {
  100. if (all[i].F - all[i - 1].F == cur)
  101. continue;
  102. ok = 0;
  103. break;
  104. }
  105.  
  106. if (ok){
  107. cout << nom + 1;
  108. return 0;
  109. }
  110.  
  111. cout << -1;
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121. return 0;
  122.  
  123.  
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement