답안 #525135

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
525135 2022-02-10T20:20:22 Z Lobo 정렬하기 (IOI15_sorting) C++17
8 / 100
2 ms 568 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], p[maxn], q[maxn], cur[maxn], posf[maxn], curf[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;
    int R = 0;
    for(int i = 0; i < n; i++) {
        a[i] = S[i];
    }
    
    for(int i = 0; i < m; i++) {
        s1[i] = X[i];
        s2[i] = Y[i];
    }

    int l = 0;
    int r1 = m;
    while(l <= r1) {
        int mid = (l+r1)>>1;

        for(int i = 0; i < n; i++) {
            posf[i] = i;
            curf[i] = i;
            pos[i] = i;
            cur[i] = i;
        }

        for(int i = 0; i < mid; i++) {
            //quero trocar cur[s1[i]] e cur[s2[i]]
            //quero trocar 
            swap(posf[curf[s1[i]]],posf[curf[s2[i]]]);
            swap(curf[s1[i]],curf[s2[i]]);
        }

        int id = 0;
        for(int i = 0; i < mid; i++) {
            swap(pos[cur[s1[i]]],pos[cur[s2[i]]]);
            swap(cur[s1[i]],cur[s2[i]]);

            while(id != n && posf[id] == a[id]) {
                id++;
            }


            if(id == n) {
                p[i] = 0;
                q[i] = 0;
                continue;
            }

            //troco a posicao do cara id com a posicao do cara que vai terminar em a[id]
            p[i] = pos[id];
            q[i] = pos[curf[a[id]]];

            swap(pos[id],pos[curf[a[id]]]);
            swap(cur[p[i]],cur[q[i]]);

            int pfid = posf[id];
            int pfaid = curf[a[id]];
            swap(posf[id],posf[curf[a[id]]]);
            swap(curf[pfid],curf[pfaid]);
            id++;
        }
        while(id != n && posf[id] == a[id]) {
            id++;
        }

        if(id == n) {
            //cara pode ser a resposta
            R = mid;
            for(int i = 0; i < mid; i++) {
                P[i] = p[i];
                Q[i] = q[i];
            }

            r1 = mid-1;
        }
        else {
            l = mid+1;
        }
    }

    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:90:27: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
   90 |                 P[i] = p[i];
      |                        ~~~^
sorting.cpp:91:27: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
   91 |                 Q[i] = q[i];
      |                        ~~~^
sorting.cpp:101:12: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
  101 |     return R;
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 296 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 1 ms 300 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 296 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 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Incorrect 1 ms 436 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Incorrect 1 ms 460 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 296 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 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Incorrect 1 ms 436 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 568 KB Output isn't correct
2 Halted 0 ms 0 KB -