-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14226 이모티콘(큐).cpp
More file actions
49 lines (43 loc) · 877 Bytes
/
Copy path14226 이모티콘(큐).cpp
File metadata and controls
49 lines (43 loc) · 877 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
43
44
45
46
47
48
49
#include<iostream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<queue>
using namespace std;
queue<pair<int, int>> q;
bool visited[2002][2002];
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int s;
cin >> s;
q.push(make_pair(1, 0));
int cnt = 0;
while (!q.empty()) {
int i = q.size();
while (i--) {
int len = q.front().first;
int clip = q.front().second;
q.pop();
if (len == s) {
cout << cnt << '\n';
return 0;
}
int c = len;
q.push(make_pair(len, c));
if (clip != -1) {
int l = len + clip;
if (!visited[l][clip] && l <= 1000) {
q.push(make_pair(l, clip));
visited[l][clip] = 1;
}
}
int l = len - 1;
if (!visited[l][clip] && 1 < l) {
q.push(make_pair(l, clip));
visited[l][clip] = 1;
}
}
cnt++;
}
}