#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
unsigned const int MAX_N = 500000;
int labels_spotted[MAX_N] = {};
int main(){
int bottle_num, label_num;
cin >> bottle_num >> label_num;
int label, last_uniq = 0;
long long seconds = 0L;
for( int i = 0; i < bottle_num && last_uniq < label_num; i++){
cin >> label;
if(labels_spotted[label] == 0) {
labels_spotted[label] = 1;
seconds += i - last_uniq;
last_uniq ++;
}
else {
}
}
if(last_uniq < label_num) seconds = -1L;
cout << seconds;
}
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 | #include <iostream> #include <vector> #include <string> #include <cstring> #include <algorithm> using namespace std; unsigned const int MAX_N = 500000; int labels_spotted[MAX_N] = {}; int main(){ int bottle_num, label_num; cin >> bottle_num >> label_num; int label, last_uniq = 0; long long seconds = 0L; for( int i = 0; i < bottle_num && last_uniq < label_num; i++){ cin >> label; if(labels_spotted[label] == 0) { labels_spotted[label] = 1; seconds += i - last_uniq; last_uniq ++; } else { } } if(last_uniq < label_num) seconds = -1L; cout << seconds; } |
English