제출 #732413

#제출 시각아이디문제언어결과실행 시간메모리
732413Programmer123Swap Swap Sort (CCO21_day1problem1)C++17
0 / 25
5032 ms1364 KiB
#include <bits/stdc++.h> int main() { int N, K, Q; std::cin >> N >> K >> Q; int data[N]; for (int i = 0; i < N; ++i) { std::cin >> data[i]; data[i]--; } int nums[K]; for (int i = 0; i < K; ++i) { nums[i] = i; } for (int _ = 0; _ < Q; ++_) { int index; std::cin >> index; std::swap(nums[index], nums[index - 1]); #ifdef LOCAL for (int i = 0; i < K; ++i) { std::cout << nums[i] << " "; } std::cout << std::endl; #endif int pos[K]; for (int i = 0; i < K; ++i) { pos[nums[i]] = i; } int sort[N]; for (int i = 0; i < N; ++i) { sort[i] = pos[data[i]]; } int swaps = 0; while (true) { for (int i = 0; i < N - 1; ++i) { if (sort[i + 1] < sort[i]) { goto unsorted; } } break; unsorted: for (int i = 0; i < N - 1; ++i) { if (sort[i + 1] < sort[i]) { std::swap(sort[i + 1], sort[i]); swaps++; } } } std::cout << swaps << std::endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...