# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
790169 | 2023-07-22T11:36:28 Z | PoonYaPat | 정렬하기 (IOI15_sorting) | C++14 | 7 ms | 10332 KB |
#include "sorting.h" #include <bits/stdc++.h> using namespace std; typedef pair<int,int> pii; int n,m,b[200005],x[200005],y[200005],p[200005],cnt; vector<pii> ans,v; vector<int> adj[200005],group[200005],temp; int a[200005],pos[200005],val[200005],c[200005]; bool vis[200005]; void dfs(int x, int st) { temp.push_back(x); vis[x]=true; for (auto s : adj[x]) { if (s==st) for (auto s : temp) group[cnt].push_back(s); else dfs(s,st); } temp.pop_back(); } bool check(int h, bool mode) { v.clear(); cnt=0; memset(vis,0,sizeof(vis)); for (int i=0; i<n; ++i) a[i]=i, val[i]=i, c[i]=b[i], p[i]=i, adj[i].clear(), group[i].clear(); for (int i=h; i>=0; --i) swap(a[x[i]],a[y[i]]); for (int i=0; i<n; ++i) pos[a[i]]=i; for (int i=0; i<n; ++i) adj[i].push_back(pos[c[i]]); for (int i=0; i<n; ++i) { if (!vis[i]) { if (adj[i][0]==i) continue; dfs(i,i); for (int j=0; j<group[cnt].size()-1; ++j) v.push_back(pii(group[cnt][j],group[cnt][j+1])); ++cnt; } } if (mode) { int cnt=0; for (int i=0; i<=h; ++i) { swap(val[p[x[i]]],val[p[y[i]]]); swap(p[x[i]],p[y[i]]); if (v.size()) { ans.push_back(pii(val[v.back().first],val[v.back().second])); v.pop_back(); } else ans.push_back(pii(0,0)); } } if (v.size()<=h+1) return true; else return false; } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { n=N; m=M; for (int i=0; i<n; ++i) b[i]=S[i], x[i]=X[i], y[i]=Y[i]; int l=0, r=m-1; while (l<r) { int mid=(l+r)/2; if (check(mid,0)) r=mid; else l=mid+1; } check(l,1); for (int i=0; i<ans.size(); ++i) P[i]=ans[i].first, Q[i]=ans[i].second; return ans.size(); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 9812 KB | Output is correct |
2 | Correct | 4 ms | 9912 KB | Output is correct |
3 | Correct | 4 ms | 9940 KB | Output is correct |
4 | Correct | 5 ms | 9812 KB | Output is correct |
5 | Correct | 4 ms | 9940 KB | Output is correct |
6 | Correct | 4 ms | 9812 KB | Output is correct |
7 | Correct | 4 ms | 9940 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 9812 KB | Output is correct |
2 | Correct | 4 ms | 9912 KB | Output is correct |
3 | Correct | 4 ms | 9940 KB | Output is correct |
4 | Correct | 5 ms | 9812 KB | Output is correct |
5 | Correct | 4 ms | 9940 KB | Output is correct |
6 | Correct | 4 ms | 9812 KB | Output is correct |
7 | Correct | 4 ms | 9940 KB | Output is correct |
8 | Correct | 4 ms | 9812 KB | Output is correct |
9 | Correct | 5 ms | 9940 KB | Output is correct |
10 | Correct | 5 ms | 9940 KB | Output is correct |
11 | Correct | 4 ms | 9940 KB | Output is correct |
12 | Correct | 6 ms | 9880 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9936 KB | Output is correct |
2 | Correct | 4 ms | 9940 KB | Output is correct |
3 | Correct | 4 ms | 9940 KB | Output is correct |
4 | Correct | 5 ms | 9972 KB | Output is correct |
5 | Correct | 5 ms | 9880 KB | Output is correct |
6 | Correct | 4 ms | 9940 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 9812 KB | Output is correct |
2 | Correct | 4 ms | 9912 KB | Output is correct |
3 | Correct | 4 ms | 9940 KB | Output is correct |
4 | Correct | 5 ms | 9812 KB | Output is correct |
5 | Correct | 4 ms | 9940 KB | Output is correct |
6 | Correct | 4 ms | 9812 KB | Output is correct |
7 | Correct | 4 ms | 9940 KB | Output is correct |
8 | Correct | 4 ms | 9812 KB | Output is correct |
9 | Correct | 5 ms | 9940 KB | Output is correct |
10 | Correct | 5 ms | 9940 KB | Output is correct |
11 | Correct | 4 ms | 9940 KB | Output is correct |
12 | Correct | 6 ms | 9880 KB | Output is correct |
13 | Correct | 6 ms | 9936 KB | Output is correct |
14 | Correct | 4 ms | 9940 KB | Output is correct |
15 | Correct | 4 ms | 9940 KB | Output is correct |
16 | Correct | 5 ms | 9972 KB | Output is correct |
17 | Correct | 5 ms | 9880 KB | Output is correct |
18 | Correct | 4 ms | 9940 KB | Output is correct |
19 | Correct | 5 ms | 9940 KB | Output is correct |
20 | Correct | 4 ms | 9812 KB | Output is correct |
21 | Correct | 7 ms | 10024 KB | Output is correct |
22 | Correct | 6 ms | 10068 KB | Output is correct |
23 | Correct | 7 ms | 10068 KB | Output is correct |
24 | Correct | 6 ms | 10068 KB | Output is correct |
25 | Correct | 7 ms | 10108 KB | Output is correct |
26 | Correct | 5 ms | 10068 KB | Output is correct |
27 | Correct | 5 ms | 10068 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 10324 KB | Output is correct |
2 | Correct | 6 ms | 10324 KB | Output is correct |
3 | Correct | 6 ms | 10332 KB | Output is correct |
4 | Incorrect | 5 ms | 10196 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 10324 KB | Output is correct |
2 | Correct | 6 ms | 10324 KB | Output is correct |
3 | Correct | 6 ms | 10332 KB | Output is correct |
4 | Incorrect | 5 ms | 10196 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |