T3000

Untitled

Feb 20th, 2022
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using ll = long long;
  5.  
  6. int main()
  7. {
  8.     ll n;
  9.     cin >> n;
  10.  
  11.     vector<pair<ll, ll>> z1;
  12.     for (int i = 0; i < n; i++)
  13.     {
  14.         ll a;
  15.         cin >> a;
  16.         z1.push_back(make_pair(a, i));
  17.     }
  18.     sort(z1.begin(), z1.end());
  19.     ll s = 1e9;
  20.  
  21.     for (int i = 0; i < n - 1; i++)
  22.     {
  23.         ll x;
  24.         if (z1.at(i).first == z1.at(i + 1).first)
  25.         {
  26.             x = z1.at(i + 1).second - z1.at(i).second;
  27.             if (x < s)
  28.             {
  29.                 s = x;
  30.             }
  31.         }
  32.     }
  33.     if (s == 1e9)
  34.     {
  35.         s = n;
  36.     }
  37.     cout << s << endl;
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment