제출 #379605

#제출 시각아이디문제언어결과실행 시간메모리
379605idk321정렬하기 (IOI15_sorting)C++11
0 / 100
2 ms492 KiB
#include "sorting.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; int n, m; int* s; int* x; int* y; int* q; int* p; bool isOk(int r) { for (int i = 0; i < m; i++) { p[i] = 0; q[i] = 0; } vector<int> change(n); for (int i = 0; i < n; i++) change[i] = i; for (int i = 0; i <= r; i++) { swap(change[x[i]], change[y[i]]); } vector<int> needed(n); for (int i = 0; i < n; i++) { needed[change[i]] = i; } vector<int> cur(s, s + n); vector<int> isOn(n); for (int i = 0; i < n; i++) { isOn[cur[i]] = i; } int check = 0; for (int i = 0; i <= r; i++) { swap(cur[x[i]], cur[y[i]]); swap(needed[x[i]], needed[y[i]]); isOn[cur[x[i]]] = x[i]; isOn[cur[y[i]]] = y[i]; while (check < n) { if (check != needed[isOn[check]]) { int a = isOn[check]; int b = isOn[needed[isOn[check]]]; swap(cur[a], cur[b]); isOn[cur[a]] = a; isOn[cur[b]] = b; p[i] = a; q[i] = b; break; } check++; } } for (int i = 1; i < n; i++) { if (cur[i] < cur[i - 1]) return false; } return true; } int bs() { int a = 0; int b = m - 1; int res = -1; while (a <= b) { int mid = (a + b) / 2; if (isOk(mid)) { res = mid; b = mid - 1; } else { a = mid + 1; } } return res; } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { n = N; m = M; s = S; x = X; y = Y; p = P; q = Q; bool alreadyGood = true; for (int i = 1; i < n; i++) { if (s[i] < s[i - 1]) alreadyGood = false; } if (alreadyGood) return 0; int best = bs() + 1; return best; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...