답안 #427223

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
427223 2021-06-14T13:27:53 Z ollel 정렬하기 (IOI15_sorting) C++17
8 / 100
48 ms 780 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;

int N;
bool sorted(int s[]) {
  rep(i,0,N) if (s[i] != i) return false;
  return true;
}

int findSwapPairs(int n, int S[], int M, int X[], int Y[], int P[], int Q[]) {
  N = n;
  int r = 0;

  while (!sorted(S)) {
    if (r > 20*n) return r;
    swap(S[X[r]], S[Y[r]]);
    if (sorted(S)) {P[r] = Q[r] = 0; return r + 1;}

    bool f = false;
    for (int mx = n; mx >= 1; mx--) {
      rep(i,0,n) {
        rep(j, 1, mx) {
          if (S[i] != X[r + i] && S[i] != Y[r + i]) {
            P[r] = i;
            Q[r] = S[i];
            swap(S[i], S[S[i]]);
            f = true;
            break;
          }
          if (f) break;
        }
        if (f) break;
      }
      if (f) break;
    }
    if (!f) P[r] = Q[r] = 0;
    r++;
  }
  return r;
}

// int main() {
//   int n = 5;
//   int S[] = {4, 3, 1, 0, 2};
//   int M;
//   int X[25] = {1, 2, 3, 4, 0}, Y[25] = {4, 0, 1, 2, 0}, P[25], Q[25];
//   cout << findSwapPairs(n, S, M, X, Y, P, Q) << endl;
//   rep (i, 0, 25) cout << P[i] << " " << Q[i] << endl;
// }

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:19:39: warning: unused parameter 'M' [-Wunused-parameter]
   19 | int findSwapPairs(int n, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                   ~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 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 1 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 0 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 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Incorrect 1 ms 332 KB Output isn't correct
11 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 Incorrect 2 ms 332 KB Output isn't correct
5 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 0 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 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Incorrect 1 ms 332 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 48 ms 780 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 48 ms 780 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -