제출 #135200

#제출 시각아이디문제언어결과실행 시간메모리
135200JustasZ정렬하기 (IOI15_sorting)C++14
0 / 100
3 ms504 KiB
/*input 5 3 0 4 2 1 5 1 1 4 0 2 3 1 4 0 4 */ /* 5 4 3 2 1 0 6 0 1 1 2 2 3 3 4 0 1 1 2 */ #include "sorting.h" #include <bits/stdc++.h> #define pb push_back #define all(a) a.begin(), a.end() #define sz(a) (int)a.size() #define x first #define y second #define debug(...) cout << "[" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "]\n" #define rd() abs((int)rng()) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int>pii; const int maxn = 2e5 + 100; const int mod = 1e9 + 7; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); int findSwapPairs(int n, int arr[], int m, int X[], int Y[], int P[], int Q[]) { auto chk = [&](int val) -> bool { vector<int>finalpos(n, 0), cur(n, 0); for(int i = 0; i < n; i++) cur[i] = i; for(int i = 0; i < val; i++) swap(cur[X[i]], cur[Y[i]]); for(int i = 0; i < n; i++) finalpos[cur[i]] = i; vector<int>where(n), v(n); for(int i = 0; i < n; i++) { v[i] = arr[i]; where[v[i]] = i; } int sw = 0; for(int i = 0; i < n; i++) { if(finalpos[i] != v[i]) { if(sw == val) return false; int pos = where[finalpos[i]]; int was = v[i]; swap(v[where[finalpos[i]]], v[i]); swap(where[finalpos[i]], where[was]); swap(finalpos[X[sw]], finalpos[Y[sw]]); swap(v[X[sw]], v[Y[sw]]); ++sw; } } return true; }; int l = 0, r = m; while(l < r) { int mid = (l + r) / 2; if(chk(mid)) r = mid; else l = mid + 1; } return l; } /*int main() { ios_base::sync_with_stdio(false), cin.tie(0); int n; cin >> n; int arr[n]; for(int i = 0; i < n; i++) cin >> arr[i]; int m; cin >> m; int X[m], Y[m]; for(int i = 0; i < m; i++) cin >> X[i] >> Y[i]; int P[m], Q[m]; cout << findSwapPairs(n, arr, m, X, Y, P, Q) << "\n"; return 0; }*/

컴파일 시 표준 에러 (stderr) 메시지

sorting.cpp: In lambda function:
sorting.cpp:64:9: warning: unused variable 'pos' [-Wunused-variable]
     int pos = where[finalpos[i]];
         ^~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:38:68: warning: unused parameter 'P' [-Wunused-parameter]
 int findSwapPairs(int n, int arr[], int m, int X[], int Y[], int P[], int Q[])
                                                                    ^
sorting.cpp:38:77: warning: unused parameter 'Q' [-Wunused-parameter]
 int findSwapPairs(int n, int arr[], int m, int X[], int Y[], int P[], int Q[])
                                                                             ^
#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...