Submission #838377

# Submission time Handle Problem Language Result Execution time Memory
838377 2023-08-26T18:08:09 Z AbdelmagedNour Sorting (IOI15_sorting) C++17
74 / 100
211 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;
//#include "grader.cpp"
#include "sorting.h"
bool check(int T,int N,int M,int S[],int X[],int Y[],int P[],int Q[]){
    vector<vector<int>>nxt(T+1,vector<int>(N));
    for(int i=0;i<N;i++)nxt[T][i]=i;
    for(int i=T-1;i>=0;i--){
        for(int j=0;j<N;j++){
            nxt[i][j]=nxt[i+1][j];
        }
        swap(nxt[i][X[i]],nxt[i][Y[i]]);
    }
    int a[N];
    for(int i=0;i<N;i++)a[i]=S[i];
    for(int i=0;i<T;i++){
        int j=0;
        swap(a[X[i]],a[Y[i]]);
        while(j<N&&a[j]==nxt[i+1][j])j++;
        if(j==N)P[i]=Q[i]=0;
        else P[i]=j,Q[i]=find(nxt[i+1].begin(),nxt[i+1].end(),a[j])-nxt[i+1].begin();
        swap(a[P[i]],a[Q[i]]);
    }
    return is_sorted(a,a+N);
}
int findSwapPairs(int N,int S[],int M,int X[],int Y[],int P[],int Q[]){
    int l=1,r=M,res=1;
    if(is_sorted(S,S+N))return 0;
    while(l<=r){
        int md=(l+r)>>1;
        if(check(md,N,M,S,X,Y,P,Q))r=(res=md)-1;
        else l=md+1;
    }
    check(res,N,M,S,X,Y,P,Q);
    return res;
}

Compilation message

sorting.cpp: In function 'bool check(int, int, int, int*, int*, int*, int*, int*)':
sorting.cpp:21:68: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   21 |         else P[i]=j,Q[i]=find(nxt[i+1].begin(),nxt[i+1].end(),a[j])-nxt[i+1].begin();
      |                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
sorting.cpp:5:28: warning: unused parameter 'M' [-Wunused-parameter]
    5 | bool check(int T,int N,int M,int S[],int X[],int Y[],int P[],int Q[]){
      |                        ~~~~^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 2 ms 852 KB Output is correct
11 Correct 1 ms 852 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 852 KB Output is correct
4 Correct 1 ms 852 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 2 ms 852 KB Output is correct
11 Correct 1 ms 852 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 852 KB Output is correct
16 Correct 1 ms 852 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 300 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 20 ms 14420 KB Output is correct
22 Correct 20 ms 14132 KB Output is correct
23 Correct 24 ms 15284 KB Output is correct
24 Correct 21 ms 14628 KB Output is correct
25 Correct 24 ms 15304 KB Output is correct
26 Correct 24 ms 14164 KB Output is correct
27 Correct 20 ms 14172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 19412 KB Output is correct
2 Correct 119 ms 22868 KB Output is correct
3 Correct 109 ms 20692 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 40 ms 23864 KB Output is correct
6 Correct 52 ms 22536 KB Output is correct
7 Correct 60 ms 24020 KB Output is correct
8 Correct 111 ms 21716 KB Output is correct
9 Correct 108 ms 22356 KB Output is correct
10 Correct 112 ms 22484 KB Output is correct
11 Correct 109 ms 23892 KB Output is correct
12 Correct 67 ms 23764 KB Output is correct
13 Correct 109 ms 23124 KB Output is correct
14 Correct 26 ms 21844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 19412 KB Output is correct
2 Correct 119 ms 22868 KB Output is correct
3 Correct 109 ms 20692 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 40 ms 23864 KB Output is correct
6 Correct 52 ms 22536 KB Output is correct
7 Correct 60 ms 24020 KB Output is correct
8 Correct 111 ms 21716 KB Output is correct
9 Correct 108 ms 22356 KB Output is correct
10 Correct 112 ms 22484 KB Output is correct
11 Correct 109 ms 23892 KB Output is correct
12 Correct 67 ms 23764 KB Output is correct
13 Correct 109 ms 23124 KB Output is correct
14 Correct 26 ms 21844 KB Output is correct
15 Runtime error 211 ms 524288 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -