Advertisement
Georgiy1108

Untitled

Nov 13th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     ios::sync_with_stdio(0);
  8.     cin.tie(0);
  9.     int t;
  10.     cin >> t;
  11.     while(t--)
  12.     {
  13.         int n;
  14.         cin >> n;
  15.         map<int, vector<int>> mp;
  16.         for(int i = 0; i < n; i++)
  17.         {
  18.             int a;
  19.             cin >> a;
  20.             mp[a].push_back(i);
  21.         }
  22.         int ans = n;
  23.         bool f = 1;
  24.         for(auto i : mp)
  25.         {
  26.             auto v = i.second;
  27.             for(int j = 0; j < v.size() - 1; j++)
  28.             {
  29.                 f = 0;
  30.                 ans = min(ans, v[j + 1] - v[j] + 1);
  31.             }
  32.         }
  33.         if(f)
  34.             cout << -1;
  35.         else
  36.             cout << ans;
  37.         cout << "\n";
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement