diff --git a/dohyeondol1/README.md b/dohyeondol1/README.md index 586986f..ecae6d3 100644 --- a/dohyeondol1/README.md +++ b/dohyeondol1/README.md @@ -9,4 +9,4 @@ | 5차시 | 2025.04.02 | DFS & BFS | [DFS와 BFS](https://www.acmicpc.net/problem/1260)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/18| | 6차시 | 2025.04.05 | DP | [평범한 배낭](https://www.acmicpc.net/problem/12865)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/22| | 7차시 | 2025.04.08 | 트리 | [트리 순회](https://www.acmicpc.net/problem/1991)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/26| - --- \ No newline at end of file + | 8차시 | 2025.04.11 | 덱 | [회전하는 큐](https://www.acmicpc.net/problem/1021)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/32| diff --git "a/dohyeondol1/\353\215\261/8-dohyeondol1.cpp" "b/dohyeondol1/\353\215\261/8-dohyeondol1.cpp" new file mode 100644 index 0000000..3602bfd --- /dev/null +++ "b/dohyeondol1/\353\215\261/8-dohyeondol1.cpp" @@ -0,0 +1,42 @@ +#include +#include +#include +#include +using namespace std; + +int main() { + cin.tie(0)->sync_with_stdio(0); + int N, M; + cin >> N >> M; + + deque dq; + for(int i = 1; i <= N; i++) + dq.push_back(i); + + vector target(M); + for(int i = 0; i < M; i++) + cin >> target[i]; + + int count = 0; + for(int i = 0; i < M; i++) { + int index = find(dq.begin(), dq.end(), target[i]) - dq.begin(); + + if(index <= dq.size()/2) { + while(index--) { + dq.push_back(dq.front()); + dq.pop_front(); + count++; + } + } else{ + int step = dq.size() - index; + while(step--) { + dq.push_front(dq.back()); + dq.pop_back(); + count++; + } + } + dq.pop_front(); + } + + cout << count << '\n'; +} \ No newline at end of file