Submission #434634

# Submission time Handle Problem Language Result Execution time Memory
434634 2021-06-21T13:33:00 Z dxz05 Sorting (IOI15_sorting) C++14
0 / 100
4 ms 588 KB
#include "sorting.h"
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1024;

int a[MAXN];

vector<pair<int, int>> ans;
void Do(int i, int j){
    swap(a[i], a[j]);
    ans.emplace_back(i, j);
}

void Do2(){
    swap(a[0], a[1]);
}

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    for (int i = 0; i < N; i++) a[i] = S[i];
    Do2();

    for (int i = 2; i < N; i++){
        if (a[i] == 0){
            for (int j = 0; j < 2; j++){
                if (a[j] > 1){
                    Do(i, j);
                    break;
                }
            }
        }
    }

    for (int i = 2; i < N; i++){
        if (a[i] == 1){
            Do2();
            for (int j = 0; j < 2; j++){
                if (a[j] > 1){
                    Do(i, j);
                    break;
                }
            }
        }
    }


    for (int i = 2; i < N; i++){
        int j = i;
        while (j < N && a[j] != i) j++;
        j--;

        if (i != j){
            Do2();
            Do(i, j);
        }

    }

    for (int i = 0; i < 10; i++){
        Do2();
        Do(0, 1);
    }

    for (int i = 0; i < ans.size(); i++){
        bool ok = true;
        for (int j = 0; j < N; j++){
            if (S[j] != j) ok = false;
        }

        if (ok) return i;

        P[i] = ans[i].first;
        Q[i] = ans[i].second;

        swap(S[0], S[1]);
        swap(S[P[i]], S[Q[i]]);
    }

	return ans.size();
}


Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:65:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |     for (int i = 0; i < ans.size(); i++){
      |                     ~~^~~~~~~~~~~~
sorting.cpp:80:17: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   80 |  return ans.size();
      |         ~~~~~~~~^~
sorting.cpp:20:39: warning: unused parameter 'M' [-Wunused-parameter]
   20 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                   ~~~~^
sorting.cpp:20:46: warning: unused parameter 'X' [-Wunused-parameter]
   20 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                          ~~~~^~~
sorting.cpp:20:55: warning: unused parameter 'Y' [-Wunused-parameter]
   20 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                                   ~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -