1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| #include <bits/stdc++.h> using namespace std; int n,ans=INT_MAX; struct ${ int s,id; }a[100005]; inline bool cmp($ p,$ q){ if (p.s!=q.s)return p.s<q.s; return p.id<q.id; } int main(void){ scanf ("%d",&n); for (int i=0;i<n;i++)scanf ("%d",&a[i].s),a[i].id=i; sort (a,a+n,cmp); for (int i=0;i<n&&a[i].s==a[i+1].s;i++)ans=min(ans,a[i+1].id-a[i].id); printf ("%d",ans); }
|