-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1700.cpp
More file actions
76 lines (60 loc) · 1.56 KB
/
1700.cpp
File metadata and controls
76 lines (60 loc) · 1.56 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include <string>
using namespace std;
int main() {
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int N;
cin >> N;
int K;
cin >> K;
int arr[101];
int search[101];
for (int i = 0; i < K; i++)cin >> arr[i];
int count = 0;
vector <int> v;
for (int i = 0; i < K; i++) {
if (v.empty()) {
v.push_back(arr[i]);
continue;
}
else {
int flag = 0;
for (int item : v) {
if (item == arr[i]) {
flag = 1;
}
}
if(flag==1)continue;
}
if (v.size() != N) {
v.push_back(arr[i]);
continue;
}
else {
fill(&search[0], &search[101], 1000);
for (int j = i; j < K; j++) {
if(search[arr[j]] > j)search[arr[j]] = j;
}
int max = 0;
int maxIdx;
for (int item : v) {
if (max < search[item]) {
max = search[item];
maxIdx = item;
}
}
for (int j = 0; j < v.size();j++) {
if (v[j] == maxIdx) {
v.erase(v.begin() + j);
count++;
v.push_back(arr[i]);
break;
}
}
}
}
cout << count;
}