# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
790050 | 2023-07-22T09:51:43 Z | peteza | 정렬하기 (IOI15_sorting) | C++14 | 2 ms | 596 KB |
#include <bits/stdc++.h> #include "sorting.h" using namespace std; int cur[200005], N; bool vis[200005]; int pos[200005]; int countcompo() { for(int j=0;j<=N;j++) vis[j] = 0; int cnt = 0; for(int i=0;i<N;i++) { if(vis[i]) continue; vis[i] = 1; cnt++; int j=i; do vis[j=cur[j]] = 1; while(j != i); } return cnt; } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { ::N = N; for(int i=0;i<N;i++) cur[i] = S[i]; memset(P, 0, 4*M); memset(Q, 0, 4 * M); if(countcompo() == N) return 0; int l=0, r=M; while(l <= r) { int mid = (l+r) >> 1; for(int i=0;i<=mid;i++) swap(cur[X[i]], cur[Y[i]]); if(N-countcompo()<=mid+1) r=mid-1; else l=mid+1; for(int i=mid;i>=0;i--) swap(cur[X[i]], cur[Y[i]]); } for(int i=l;i<M;i++) { swap(cur[X[i]], cur[Y[i]]); int cnt = N-countcompo(); if(cnt <= i+1) { //check if after swapping i, minimum is less than that of i+1 //if so then return memset(vis, 0, sizeof vis); vector<pair<int, int>> ans; for(int i=0;i<N;i++) { if(!vis[i]) { vis[i] = 1; int l = i, j = cur[i]; while(j != i) { vis[j] = 1; ans.emplace_back(l, j); l = j; j = cur[j]; } } } //cout << ans.size() << ": \n"; //for(auto e:ans) cout << e.first << ' ' << e.second << '\n'; int k = 0; for(int i=0;i<N;i++) pos[S[i]] = i; for(int j=0;j<=i;j++) { swap(pos[S[X[j]]], pos[S[Y[j]]]); swap(S[X[j]], S[Y[j]]); if(!ans.empty()) { P[k] = pos[ans.back().first]; Q[k++] = pos[ans.back().second]; ans.pop_back(); } } return i+1; } } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 416 KB | Output is correct |
4 | Correct | 1 ms | 468 KB | Output is correct |
5 | Correct | 1 ms | 468 KB | Output is correct |
6 | Correct | 1 ms | 468 KB | Output is correct |
7 | Correct | 1 ms | 436 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 416 KB | Output is correct |
4 | Correct | 1 ms | 468 KB | Output is correct |
5 | Correct | 1 ms | 468 KB | Output is correct |
6 | Correct | 1 ms | 468 KB | Output is correct |
7 | Correct | 1 ms | 436 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 312 KB | Output is correct |
10 | Correct | 1 ms | 468 KB | Output is correct |
11 | Correct | 1 ms | 468 KB | Output is correct |
12 | Correct | 1 ms | 448 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Incorrect | 1 ms | 436 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 416 KB | Output is correct |
4 | Correct | 1 ms | 468 KB | Output is correct |
5 | Correct | 1 ms | 468 KB | Output is correct |
6 | Correct | 1 ms | 468 KB | Output is correct |
7 | Correct | 1 ms | 436 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 312 KB | Output is correct |
10 | Correct | 1 ms | 468 KB | Output is correct |
11 | Correct | 1 ms | 468 KB | Output is correct |
12 | Correct | 1 ms | 448 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Incorrect | 1 ms | 436 KB | Output isn't correct |
15 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 596 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 596 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |