Submission #1235976

#TimeUsernameProblemLanguageResultExecution timeMemory
1235976santi3223정렬하기 (IOI15_sorting)C++20
20 / 100
2 ms840 KiB
#include <bits/stdc++.h> //#include "sorting.h" using namespace std; #define ll long long #define vb vector<bool> #define pb push_back #define ff(aa, bb, cc) for(ll aa = bb; aa < cc; aa++) #define vl vector<ll> #define pll pair<ll, ll> #define fi first #define se second #define ed "\n" #define all(aaa) aaa.begin(), aaa.end() #define rall(aaa) aaa.rbegin(), aaa.rend() int findSwapPairs(int n, int S[], int M, int X[], int Y[], int P[], int Q[]) { vl arr; ff(i, 0, n){ arr.pb(S[i]); } map<ll, vl> mp; vl sorted = arr; sort(all(sorted)); map<ll, vl> fin; ff(i, 0, n){ if(arr[i] != sorted[i]){ fin[sorted[i]].pb(i); } } ff(i, 0, n){ if(arr[i] != sorted[i]){ mp[arr[i]].pb(i); } } ll c = 0; vl a, b; ff(i, 0, n){ //cout << arr[i] << " " << sorted[i] << ed; if(arr[i] == sorted[i]){ continue; } c++; ll sup = sorted[i]; ll aux = 0; /*ff(id, 0, n){ cout << arr[id] << " "; } cout << ed; cout << arr[i] << " " << sorted[i] << ed;*/ for(auto &p : mp[sup]){ aux = p; if(sorted[p] == arr[i]){ break; } } //cout << "P " << i << " " << aux << ed; for(auto &p : mp[arr[i]]){ //cout << p << " "; if(p == i){ p = aux; break; } } //cout << ed; for(auto &p : mp[arr[aux]]){ //cout << p << " "; if(p == aux){ p = i; } } //cout << ed << ed; a.pb(i); b.pb(aux); //cout << i << " " << aux << ed; swap(arr[i], arr[aux]); } ff(i, 0, a.size()){ P[i] = a[i]; Q[i] = b[i]; } return c; } /* int main() { ios::sync_with_stdio(0); cin.tie(0); int N, M; cin >> N; vector<int> S(N); ff(i, 0, N) cin >> S[i]; cin >> M; vector<int> X(M), Y(M); ff(i, 0, M) cin >> X[i] >> Y[i]; vector<int> P, Q; int ans = findSwapPairs(N, S, M, X, Y, P, Q); cout << ans << ed; ff(i, 0, ans) { cout << P[i] << " " << Q[i] << ed; } return 0; } */
#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...