1 solutions
-
0
#include<bits/stdc++.h> using namespace std; typedef long long ll; multiset<ll>::iterator itt; const int N = 2e5+111, P = 998244353; int n; int a[N]; unordered_map<int, int> mp; void work(){ scanf("%d",&n); int minn = n + 11; for(int i=1;i<=n;i++){ scanf("%d",&a[i]); if(mp[a[i]]) minn = min(minn, i - mp[a[i]] + 1); mp[a[i]] = i; } if(minn == n + 11) minn = -1; printf("%d\n",minn); } int main(){ int t = 1; //scanf("%d",&t); while(t--) work(); return 0; }
- 1
Information
- ID
- 535
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 8
- Tags
- (None)
- # Submissions
- 15
- Accepted
- 5
- Uploaded By