-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathawkwardparty.cpp
More file actions
42 lines (37 loc) · 872 Bytes
/
Copy pathawkwardparty.cpp
File metadata and controls
42 lines (37 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define ar array
#define ll long long
void solve() {
int n;
cin>>n;
unordered_map<int,vector<int> > lang_idx;
for(int i=0;i<n;i++){
int x;
cin>>x;
if(lang_idx.find(x)==lang_idx.end()){
lang_idx[x]=vector<int>();
}
lang_idx[x].push_back(i);
}
int awks=n;
for(auto it=lang_idx.begin();it!=lang_idx.end();it++){
vector<int> &idxs=it->second;
for(int i=0;i<idxs.size()-1;i++){
int dist=idxs[i+1]-idxs[i];
awks=min(awks, dist);
}
}
cout<<awks<<endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int tc = 1;
// cin >> tc;
for (int t = 1; t <= tc; t++) {
// cout << "Case #" << t << ": ";
solve();
}
}