답안 #426853

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
426853 2021-06-14T10:29:22 Z ollel 정렬하기 (IOI15_sorting) C++17
20 / 100
2 ms 332 KB
#include <bits/stdc++.h>
#include <iostream>
using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define pb push_back
#define lso(x) x&(-x)

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;

#include <bits/stdc++.h>
#include <iostream>
using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define pb push_back
#define lso(x) x&(-x)

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;


int findSwapPairsS(int n, int S[], int M, int X[], int Y[], int P[], int Q[]) {
  vi to(n), from(n);

  rep(i,0,n) to[i] = S[i];
  rep(i,0,n) from[S[i]] = i;

  int r = 0;

  rep(i, 0, n) if (S[i] == 0) {
    swap(S[i], S[0]);
    P[r] = 0;
    Q[r] = i;
    swap(S[0], S[1]);
    r++;
  }

  rep(i, 0, n) if (S[i] == 1) {
    swap(S[i], S[0]);
    P[r] = 0;
    Q[r] = 1;
    swap(S[0], S[1]);
    r++;
  }

  rep(i,2,n) {
    while (S[i] != i) {
      int nw = S[S[i]];
      P[r] = i; Q[r] = S[i];
      swap(S[i], S[S[i]]);
      swap(S[0], S[1]);
      r++;
    }
  }

  if (S[0] != 0) {
    P[r] = Q[r] = 0;
    r++;
  }

  return r;
}

int findSwapPairs(int n, int S[], int M, int X[], int Y[], int P[], int Q[]) {
  if (Y[0] == 1) return findSwapPairsS(n, S, M, X, Y, P, Q);
  vi to(n), from(n);

  rep(i,0,n) to[i] = S[i];
  rep(i,0,n) from[S[i]] = i;

  int r = 0;
  rep(i,0,n) {
    while (S[i] != i) {
      int nw = S[S[i]];
      P[r] = i; Q[r] = S[i];
      swap(S[i], S[S[i]]);
      r++;
    }
  }
  return r;
}

Compilation message

sorting.cpp: In function 'int findSwapPairsS(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:52:11: warning: unused variable 'nw' [-Wunused-variable]
   52 |       int nw = S[S[i]];
      |           ^~
sorting.cpp:26:40: warning: unused parameter 'M' [-Wunused-parameter]
   26 | int findSwapPairsS(int n, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                    ~~~~^
sorting.cpp:26:47: warning: unused parameter 'X' [-Wunused-parameter]
   26 | int findSwapPairsS(int n, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                           ~~~~^~~
sorting.cpp:26:56: warning: unused parameter 'Y' [-Wunused-parameter]
   26 | int findSwapPairsS(int n, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                                    ~~~~^~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:78:11: warning: unused variable 'nw' [-Wunused-variable]
   78 |       int nw = S[S[i]];
      |           ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Incorrect 1 ms 204 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -