File tree Expand file tree Collapse file tree 1 file changed +43
-2
lines changed Expand file tree Collapse file tree 1 file changed +43
-2
lines changed Original file line number Diff line number Diff line change 1
- // Authored by : BaaaaaaaaaaarkingDog
1
+ // Authored by : sukam09
2
2
// Co-authored by : -
3
- // http://boj.kr/****************
3
+ // http://boj.kr/03e21675c9ef49a8b6f1ee6838a44aeb
4
4
#include < bits/stdc++.h>
5
5
using namespace std ;
6
6
7
+ #define X first
8
+ #define Y second
9
+
10
+ int a[105 ]; // 전기용품의 사용 순서
11
+ bool power[105 ]; // 해당 전기용품이 멀티탭에 꽂혀 있는가?
12
+
7
13
int main (void ){
8
14
ios::sync_with_stdio (0 );
9
15
cin.tie (0 );
10
16
17
+ int n, k;
18
+ cin >> n >> k;
19
+ for (int i = 1 ; i <= k; i++) cin >> a[i];
20
+ int ans = 0 ;
21
+ int cnt = 0 ; // 멀티탭에 꽂혀 있는 전기용품의 개수
22
+ for (int i = 1 ; i <= k; i++) {
23
+ int cur = a[i];
24
+ if (power[cur]) continue ; // 이미 꽂혀 있으면 넘어감
25
+ // 멀티탭에 자리가 남으면 그냥 꽂음
26
+ if (cnt < n) {
27
+ power[cur] = true ;
28
+ cnt++;
29
+ }
30
+ else {
31
+ // 멀티탭에 꽂혀 있는 전기용품 중 a에서 앞으로 가장 빨리 나올 위치를 이름과 함께 저장함
32
+ vector<pair<int , int >> idx;
33
+ for (int x = 1 ; x <= k; x++) {
34
+ if (!power[x]) continue ;
35
+ bool vis = false ;
36
+ for (int y = i + 1 ; y <= k; y++) {
37
+ if (a[y] == x) {
38
+ idx.push_back ({y, x});
39
+ vis = true ;
40
+ break ;
41
+ }
42
+ }
43
+ if (!vis) idx.push_back ({k + 1 , x}); // a에서 나오지 않으면 k + 1로 처리
44
+ }
45
+ sort (idx.begin (), idx.end (), greater<pair<int , int >>());
46
+ int target = idx[0 ].Y ; // 가장 늦게 사용할 전기용품을 뽑고 cur을 꽂으면 됨
47
+ power[target] = false ; ans++;
48
+ power[cur] = true ;
49
+ }
50
+ }
51
+ cout << ans;
11
52
}
You can’t perform that action at this time.
0 commit comments