# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
485849 | 2021-11-09T14:22:40 Z | MilosMilutinovic | 정렬하기 (IOI15_sorting) | C++14 | 1000 ms | 11796 KB |
#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef vector<int> VI; typedef long long ll; typedef pair<int,int> PII; typedef double db; mt19937 mrand(random_device{}()); const ll mod=1000000007; const ll mod2=998244353; int rnd(int x) { return mrand() % x;} ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} // head const int N=201000; int n,a[N],s[N],id[N],pos[N],x[N],y[N]; bool check(int r) { rep(i,0,n) a[i]=s[i],id[i]=i; rep(i,0,r) { swap(a[x[i]],a[y[i]]); } rep(i,0,n) pos[a[i]]=i; int cnt=0; rep(i,0,n) { if (pos[i]==i) continue; int w=a[i]; swap(a[pos[i]],a[i]); swap(pos[i],pos[w]); cnt++; } return cnt<=r; } void gao(int r,int* p,int* q) { rep(i,0,n) a[i]=s[i],id[i]=i; rep(i,0,r) { swap(a[x[i]],a[y[i]]); } rep(i,0,n) pos[a[i]]=i; int cnt=0; vector<PII> todo; rep(i,0,n) { if (pos[i]==i) continue; todo.pb(mp(i,a[i])); int w=a[i]; swap(a[pos[i]],a[i]); swap(pos[i],pos[w]); } assert(is_sorted(a,a+n)); rep(i,0,n) a[i]=s[i]; rep(i,0,r) { swap(a[x[i]],a[y[i]]); if (i<SZ(todo)) { rep(j,0,n) if (a[j]==todo[i].fi) p[i]=j; rep(j,0,n) if (a[j]==todo[i].se) q[i]=j; swap(a[p[i]],a[q[i]]); } else p[i]=q[i]=0; } //rep(i,0,n) printf("%d ",a[i]); puts(""); //assert(is_sorted(a,a+n)); rep(i,SZ(todo),r) p[i]=q[i]=0; } int findSwapPairs(int n,int* s,int m,int* x,int* y,int* p,int* q) { if (is_sorted(s,s+n)) return 0; ::n=n; rep(i,0,n) ::s[i]=s[i]; rep(i,0,m) ::x[i]=x[i],::y[i]=y[i]; int l=1,r=n,ans=1; while (l<=r) { int md=l+r>>1; if (check(md)) ans=md,r=md-1; else l=md+1; } gao(ans,p,q); return ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 0 ms | 332 KB | Output is correct |
6 | Correct | 0 ms | 332 KB | Output is correct |
7 | Correct | 0 ms | 332 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 0 ms | 332 KB | Output is correct |
6 | Correct | 0 ms | 332 KB | Output is correct |
7 | Correct | 0 ms | 332 KB | Output is correct |
8 | Correct | 0 ms | 204 KB | Output is correct |
9 | Correct | 1 ms | 204 KB | Output is correct |
10 | Correct | 0 ms | 332 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 0 ms | 332 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 0 ms | 332 KB | Output is correct |
6 | Correct | 0 ms | 332 KB | Output is correct |
7 | Correct | 0 ms | 332 KB | Output is correct |
8 | Correct | 0 ms | 204 KB | Output is correct |
9 | Correct | 1 ms | 204 KB | Output is correct |
10 | Correct | 0 ms | 332 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 0 ms | 204 KB | Output is correct |
14 | Correct | 1 ms | 332 KB | Output is correct |
15 | Correct | 1 ms | 332 KB | Output is correct |
16 | Correct | 1 ms | 332 KB | Output is correct |
17 | Correct | 0 ms | 332 KB | Output is correct |
18 | Correct | 0 ms | 204 KB | Output is correct |
19 | Correct | 0 ms | 204 KB | Output is correct |
20 | Correct | 0 ms | 204 KB | Output is correct |
21 | Correct | 1 ms | 460 KB | Output is correct |
22 | Correct | 1 ms | 588 KB | Output is correct |
23 | Correct | 1 ms | 588 KB | Output is correct |
24 | Correct | 1 ms | 460 KB | Output is correct |
25 | Correct | 1 ms | 588 KB | Output is correct |
26 | Correct | 1 ms | 588 KB | Output is correct |
27 | Correct | 1 ms | 460 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 460 KB | Output is correct |
2 | Correct | 7 ms | 516 KB | Output is correct |
3 | Correct | 7 ms | 504 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 460 KB | Output is correct |
6 | Correct | 2 ms | 460 KB | Output is correct |
7 | Correct | 4 ms | 460 KB | Output is correct |
8 | Correct | 8 ms | 460 KB | Output is correct |
9 | Correct | 7 ms | 460 KB | Output is correct |
10 | Correct | 6 ms | 460 KB | Output is correct |
11 | Correct | 6 ms | 460 KB | Output is correct |
12 | Correct | 4 ms | 500 KB | Output is correct |
13 | Correct | 6 ms | 512 KB | Output is correct |
14 | Correct | 1 ms | 460 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 460 KB | Output is correct |
2 | Correct | 7 ms | 516 KB | Output is correct |
3 | Correct | 7 ms | 504 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 460 KB | Output is correct |
6 | Correct | 2 ms | 460 KB | Output is correct |
7 | Correct | 4 ms | 460 KB | Output is correct |
8 | Correct | 8 ms | 460 KB | Output is correct |
9 | Correct | 7 ms | 460 KB | Output is correct |
10 | Correct | 6 ms | 460 KB | Output is correct |
11 | Correct | 6 ms | 460 KB | Output is correct |
12 | Correct | 4 ms | 500 KB | Output is correct |
13 | Correct | 6 ms | 512 KB | Output is correct |
14 | Correct | 1 ms | 460 KB | Output is correct |
15 | Execution timed out | 1088 ms | 11796 KB | Time limit exceeded |
16 | Halted | 0 ms | 0 KB | - |