답안 #438699

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
438699 2021-06-28T13:37:43 Z NintsiChkhaidze 정렬하기 (IOI15_sorting) C++14
20 / 100
3 ms 460 KB
#include "sorting.h"
#include <bits/stdc++.h>
#define s second
#define f first
#define pii pair<int,int>
using namespace std;
int idx[200005],a[200005];
pii d[200005];

int findSwapPairs(int N, int S[], int M, int x[], int y[], int p[], int q[]) {
    bool c = 1;
    for (int i=0;i<N;i++)
        if (S[i] != i) c=0;
    
    if (c) return 0;
    
    int l = 1,r = M,ans = 0;
    while(l <= r){
        int mid = (l+r)>>1;
        
        for (int i=0;i<N;i++){
            a[i] = S[i];
            idx[S[i]] = i;
        }
        
        for (int i = 0; i < mid; i++){
            swap(a[x[i]],a[y[i]]);
            swap(idx[a[x[i]]],idx[a[y[i]]]);
        }
       
        int cnt = 0;
        for (int i = 0; i < N; i++){
            if (a[i] == i) continue;
            
            d[cnt] = {a[i],i};
            cnt++;
            
            int ind = idx[i];
            swap(idx[a[i]],idx[i]);
            swap(a[i],a[ind]);
        }
        
        if (cnt <= mid){
            ans = mid;
            for (int i=0;i<N;i++){
                a[i] = S[i];
                idx[S[i]] = i;
            }
            
            for (int i = 0; i < mid; i++){
                swap(a[x[i]],a[y[i]]);
                swap(idx[a[x[i]]],idx[a[y[i]]]);
                
                p[i] = d[i].f; q[i] = d[i].s;
                swap(idx[p[i]],idx[q[i]]);
                p[i] = idx[p[i]]; q[i] = idx[q[i]];
                swap(a[p[i]],a[q[i]]);
             }
            r = mid - 1;
        }
        else {
            l = mid + 1;
        }
    }
    
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 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 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Incorrect 1 ms 204 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 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 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Incorrect 1 ms 204 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Incorrect 3 ms 460 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Incorrect 3 ms 460 KB Output isn't correct
4 Halted 0 ms 0 KB -