-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path210308_BOJ_1713.cpp
More file actions
93 lines (70 loc) · 1.34 KB
/
Copy path210308_BOJ_1713.cpp
File metadata and controls
93 lines (70 loc) · 1.34 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main() {
int N, M;
cin >> N;
cin >> M;
vector<int> p;
map<int, int> m;
for (int i = 0; i < M; ++i) {
int c; cin >> c;
auto it = m.find(c);
if (p.size() == N && it == m.end()) {
int Min = 0;
for (int i = 1; i < N; ++i) {
if (m[p[Min]] > m[p[i]])
Min = i;
}
m.erase(p[Min]);
p.erase(p.begin() + Min);
m[c] = 0;
}
if (it == m.end())
p.push_back(c);
m[c]++;
}
for (auto &it : m)
cout << it.first << " ";
cout << "\n";
return 0;
}
// // 210113
// #include <iostream>
// #include <vector>
// using namespace std;
// int N = 0;
// int M = 0;
// vector<int> isIn;
// vector<int> c;
// int main() {
// cin >> N;
// cin >> M;
// isIn.assign(M + 1, 0);
// for (int i = 0; i < M; ++i) {
// int t; cin >> t;
// if (isIn[t] == 0) { // 새로운 추천
// if (c.size() == N) {
// int Min = isIn[c[0]];
// int index = 0;
// for (int i = 1; i < c.size(); ++i) {
// if (Min > isIn[c[i]]) {
// Min = isIn[c[i]];
// index = i;
// }
// }
// isIn[c[index]] = 0;
// c.erase(c.begin() + index);
// }
// c.push_back(t);
// }
// isIn[t]++;
// }
// for (int i = 1; i < isIn.size(); ++i) {
// if (isIn[i] > 0)
// cout << i << " ";
// }
// cout << "\n";
// return 0;
// }