# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
958615 | 2024-04-06T07:15:31 Z | 12345678 | 정렬하기 (IOI15_sorting) | C++17 | 2 ms | 2600 KB |
#include "sorting.h" #include <bits/stdc++.h> using namespace std; const int nx=2e5+5; int s[nx], rs[nx], loc[nx], idx[nx], ridx[nx], n; int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { n=N; int l=0, r=N-1; while (l<=r) { int md=(l+r)/2, cnt=0, cur=0; for (int i=0; i<N; i++) idx[i]=i, ridx[i]=i, s[i]=S[i], rs[s[i]]=i; for (int i=md-1; i>=0; i--) swap(idx[X[i]], idx[Y[i]]), swap(ridx[idx[X[i]]], ridx[idx[Y[i]]]); //cout<<"debug "<<l<<' '<<r<<' '<<md<<'\n'; for (int i=0; i<md; i++) { swap(ridx[idx[X[i]]], ridx[idx[Y[i]]]); swap(idx[X[i]], idx[Y[i]]); swap(s[X[i]], s[Y[i]]); swap(rs[s[X[i]]], rs[s[Y[i]]]); /* cout<<"idx "<<md<<':'; for (int j=0; j<N; j++) cout<<idx[j]<<' '; cout<<'\n'; cout<<"ridx "<<md<<':'; for (int j=0; j<N; j++) cout<<ridx[j]<<' '; cout<<'\n'; cout<<"s "<<md<<':'; for (int j=0; j<N; j++) cout<<s[j]<<' '; cout<<'\n'; cout<<"rs "<<md<<':'; for (int j=0; j<N; j++) cout<<rs[j]<<' '; cout<<'\n'; */ while (cur<N&&ridx[cur]==rs[cur]) cur++; if (cur<N) P[cnt]=ridx[cur], Q[cnt]=rs[cur], swap(s[P[cnt]], s[Q[cnt]]), swap(rs[s[P[cnt]]], rs[s[Q[cnt]]]), cur++, cnt++; while (cur<N&&ridx[cur]==rs[cur]) cur++; } //cout<<"debug "<<l<<' '<<r<<' '<<cur<<' '<<md<<'\n'; if (l==r) return l; if (cur<N) l=md+1; else r=md; } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 1 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Correct | 1 ms | 2396 KB | Output is correct |
5 | Correct | 1 ms | 2396 KB | Output is correct |
6 | Correct | 1 ms | 2396 KB | Output is correct |
7 | Correct | 1 ms | 2396 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 1 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Correct | 1 ms | 2396 KB | Output is correct |
5 | Correct | 1 ms | 2396 KB | Output is correct |
6 | Correct | 1 ms | 2396 KB | Output is correct |
7 | Correct | 1 ms | 2396 KB | Output is correct |
8 | Correct | 1 ms | 2392 KB | Output is correct |
9 | Correct | 1 ms | 2396 KB | Output is correct |
10 | Correct | 1 ms | 2396 KB | Output is correct |
11 | Correct | 1 ms | 2396 KB | Output is correct |
12 | Correct | 1 ms | 2396 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2392 KB | Output is correct |
2 | Correct | 1 ms | 2392 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Correct | 1 ms | 2396 KB | Output is correct |
5 | Correct | 1 ms | 2396 KB | Output is correct |
6 | Correct | 1 ms | 2396 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 1 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Correct | 1 ms | 2396 KB | Output is correct |
5 | Correct | 1 ms | 2396 KB | Output is correct |
6 | Correct | 1 ms | 2396 KB | Output is correct |
7 | Correct | 1 ms | 2396 KB | Output is correct |
8 | Correct | 1 ms | 2392 KB | Output is correct |
9 | Correct | 1 ms | 2396 KB | Output is correct |
10 | Correct | 1 ms | 2396 KB | Output is correct |
11 | Correct | 1 ms | 2396 KB | Output is correct |
12 | Correct | 1 ms | 2396 KB | Output is correct |
13 | Correct | 1 ms | 2392 KB | Output is correct |
14 | Correct | 1 ms | 2392 KB | Output is correct |
15 | Correct | 1 ms | 2396 KB | Output is correct |
16 | Correct | 1 ms | 2396 KB | Output is correct |
17 | Correct | 1 ms | 2396 KB | Output is correct |
18 | Correct | 1 ms | 2396 KB | Output is correct |
19 | Correct | 1 ms | 2396 KB | Output is correct |
20 | Correct | 1 ms | 2396 KB | Output is correct |
21 | Correct | 2 ms | 2568 KB | Output is correct |
22 | Correct | 1 ms | 2396 KB | Output is correct |
23 | Correct | 1 ms | 2396 KB | Output is correct |
24 | Correct | 1 ms | 2396 KB | Output is correct |
25 | Correct | 1 ms | 2396 KB | Output is correct |
26 | Incorrect | 2 ms | 2396 KB | Output isn't correct |
27 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 2 ms | 2600 KB | Output is correct |
3 | Incorrect | 1 ms | 2396 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 2 ms | 2600 KB | Output is correct |
3 | Incorrect | 1 ms | 2396 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |