【codeforces 19/11/13 div2】C. Dominated Subarray

 1 #include<iostream>
 2 #include<cstring>
 3 #include<vector>
 4 using namespace std;
 5 
 6 const int maxn = 200010;
 7 vector<int>nextval[maxn];
 8 
 9 inline int min(int a, int b)
10 {
11     return a < b ? a : b;
12 }
13 
14 int main()
15 {
16     int T;
17     cin >> T;
18     while (T--)
19     {
20         int n;
21         cin >> n;
22         for (int i = 1; i <= n; i++)
23         {
24             int t;
25             cin >> t;
26             nextval[t].push_back(i);
27         }
28         if (n == 1)
29         {
30             cout << -1 << endl;
31             continue;
32         }
33         int ans = n;
34         int f = true;
35         for (int i = 1; i < maxn; i++)
36         {
37             for (int j = 1; j < nextval[i].size(); j++)
38             {
39                 f = false;
40                 ans = min(ans, nextval[i][j] - nextval[i][j - 1] + 1);
41             }
42             nextval[i].clear();
43         }
44         if (ans == n && f) cout << -1 << endl;
45         else cout << ans << endl;
46     }
47 }
View Code

 

posted on 2019-11-14 11:04  thjkhdf12  阅读(102)  评论(0)    收藏  举报