답안 #525165

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
525165 2022-02-11T00:06:24 Z Lobo 정렬하기 (IOI15_sorting) C++17
74 / 100
42 ms 18788 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 = posf[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 0 ms 332 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 288 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 288 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 300 KB Output is correct
9 Correct 0 ms 296 KB Output is correct
10 Correct 1 ms 436 KB Output is correct
11 Correct 1 ms 436 KB Output is correct
12 Correct 1 ms 436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 0 ms 296 KB Output is correct
3 Correct 1 ms 436 KB Output is correct
4 Correct 1 ms 428 KB Output is correct
5 Correct 1 ms 436 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 288 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 300 KB Output is correct
9 Correct 0 ms 296 KB Output is correct
10 Correct 1 ms 436 KB Output is correct
11 Correct 1 ms 436 KB Output is correct
12 Correct 1 ms 436 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 0 ms 296 KB Output is correct
15 Correct 1 ms 436 KB Output is correct
16 Correct 1 ms 428 KB Output is correct
17 Correct 1 ms 436 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 292 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 2 ms 940 KB Output is correct
22 Correct 2 ms 976 KB Output is correct
23 Correct 2 ms 932 KB Output is correct
24 Correct 1 ms 932 KB Output is correct
25 Correct 1 ms 944 KB Output is correct
26 Correct 2 ms 956 KB Output is correct
27 Correct 2 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 2 ms 696 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 696 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 684 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 2 ms 716 KB Output is correct
12 Correct 2 ms 716 KB Output is correct
13 Correct 2 ms 716 KB Output is correct
14 Correct 1 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 2 ms 696 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 696 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 684 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 2 ms 716 KB Output is correct
12 Correct 2 ms 716 KB Output is correct
13 Correct 2 ms 716 KB Output is correct
14 Correct 1 ms 632 KB Output is correct
15 Runtime error 42 ms 18788 KB Execution killed with signal 11
16 Halted 0 ms 0 KB -