답안 #1053830

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1053830 2024-08-11T18:14:19 Z Osplei 정렬하기 (IOI15_sorting) C++17
16 / 100
1 ms 348 KB
#include "sorting.h"
#include <bits/stdc++.h>

using namespace std;

#define pb push_back

typedef long long ll;
typedef pair <ll, ll> LL;

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {

  vector <int> orden;
  int ans = 0, pos = 0;

  for (int i = 0; i < N; i++) {
    orden.pb(S[i]);
  }

  sort(orden.begin(), orden.end());

  if (N == 1) return 0;

  if (S[0] != orden[0]){
    ans++;

    swap(S[0], S[1]);

    if (orden[0] == S[0]) {
      
      P[pos] = 0;
      Q[pos] = 0;
      pos++;

    } else {

      for (int j = 1; j < N; j++) {
        if (orden[0] == S[j]) {

          swap(S[0], S[j]);

          P[pos] = 0;
          Q[pos] = j;

          pos++;

          break;
        }
      }

    }
  }

  if (S[1] != orden[1]){
    ans++;

    swap(S[0], S[1]);

    if (orden[1] == S[1]) {
    
      P[pos] = 0;
      Q[pos] = 0;
      pos++;
    
    } else {

      for (int j = 1; j < N; j++) {
        if (orden[1] == S[j]) {

          swap(S[0], S[j]);

          P[pos] = 0;
          Q[pos] = j;

          pos++;

          break;
        }
      }
    }
  }

  for (int i = 2; i < N; i++) {

    if (orden[i] != S[i]) {
      
      ans++;
      
      swap(S[0], S[1]);
      
      for (int j = i; j < N; j++) {
        if (orden[i] == S[j]) {

          swap(S[i], S[j]);

          P[pos] = i;
          Q[pos] = j;

          pos++;

          break;
        }
      }
    }

  }
  
  if (S[0] > S[1]) {
    ans++;
    P[pos] = 0;
    Q[pos] = 0;
    pos++;
  } 

  return ans;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:11:39: warning: unused parameter 'M' [-Wunused-parameter]
   11 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                   ~~~~^
sorting.cpp:11:46: warning: unused parameter 'X' [-Wunused-parameter]
   11 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                          ~~~~^~~
sorting.cpp:11:55: warning: unused parameter 'Y' [-Wunused-parameter]
   11 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                                   ~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -