답안 #524565

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
524565 2022-02-09T13:58:59 Z Lobo 정렬하기 (IOI15_sorting) C++17
36 / 100
1 ms 684 KB
#include "sorting.h"
#include<bits/stdc++.h>
using namespace std;

const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

#define maxn 55000

int n, m, a[maxn], pos[maxn], s1[maxn], s2[maxn];

int32_t findSwapPairs(int32_t N, int32_t S[], int32_t M, int32_t X[], int32_t Y[], int32_t P[], int32_t Q[]) {
    n = N;
    m = M;
    for(int i = 0; i < n; i++) {
        a[i] = S[i];
        pos[a[i]] = i;
    }
    
    for(int i = 0; i < m; i++) {
        s1[i] = X[i];
        s2[i] = Y[i];
    }

    int32_t R = 0;
    if(Y[0] != 1) {
        for(int i = 0; i < n; i++) {
            if(pos[i] != i) {
                //swap a[i] and a[pos[i]]
                P[R] = i;
                Q[R] = pos[i];
                //pos[i] = i
                //pos[a[i]] = pos[i]
                swap(pos[i],pos[a[i]]);
                swap(a[P[R]],a[Q[R]]);
                R++;
            }
        }
    }
    else {
        //colocar 0 na posicao 0 e 1 na pos 1
        
        //colocar 0 na posicao 0
        swap(pos[a[0]],pos[a[1]]);
        swap(a[0],a[1]);

        P[R] = 0;
        Q[R] = pos[0];
        //pos[i] = i
        //pos[a[i]] = pos[i]
        swap(pos[0],pos[a[0]]);
        swap(a[P[R]],a[Q[R]]);
        R++;

        //colocar 1 na posicao 0
        swap(pos[a[0]],pos[a[1]]);
        swap(a[0],a[1]);

        P[R] = 0;
        Q[R] = pos[1];
        //pos[i] = i
        //pos[a[i]] = pos[i]
        swap(pos[a[0]],pos[1]);
        swap(a[P[R]],a[Q[R]]);
        R++;
        
        for(int i = 2; i < n; i++) {
            if(pos[i] != i) {
                //swap a[i] and a[pos[i]]
                swap(pos[a[0]],pos[a[1]]);
                swap(a[0],a[1]);
                P[R] = i;
                Q[R] = pos[i];
                //pos[i] = i
                //pos[a[i]] = pos[i]
                swap(pos[i],pos[a[i]]);
                swap(a[P[R]],a[Q[R]]);
                R++;
            }
        }

        if(a[0] == 1) {
            swap(pos[a[0]],pos[a[1]]);
            swap(a[0],a[1]);
            P[R] = 0;
            Q[R] = 0;
            //pos[i] = i
            //pos[a[i]] = pos[i]
            R++;
        }
    }

    return R;
}

Compilation message

sorting.cpp: In function 'int32_t findSwapPairs(int32_t, int32_t*, int32_t, int32_t*, int32_t*, int32_t*, int32_t*)':
sorting.cpp:38:24: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
   38 |                 P[R] = i;
      |                        ^
sorting.cpp:39:29: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
   39 |                 Q[R] = pos[i];
      |                        ~~~~~^
sorting.cpp:56:21: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
   56 |         Q[R] = pos[0];
      |                ~~~~~^
sorting.cpp:68:21: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
   68 |         Q[R] = pos[1];
      |                ~~~~~^
sorting.cpp:80:24: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
   80 |                 P[R] = i;
      |                        ^
sorting.cpp:81:29: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
   81 |                 Q[R] = pos[i];
      |                        ~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 296 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 300 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 296 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 296 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 300 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 0 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 308 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 296 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 300 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 0 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 308 KB Output is correct
18 Correct 1 ms 292 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 292 KB Output is correct
21 Incorrect 1 ms 684 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 432 KB Output isn't correct
2 Halted 0 ms 0 KB -