# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
385082 | 2021-04-03T06:59:46 Z | qpwoeirut | 정렬하기 (IOI15_sorting) | C++17 | 2 ms | 620 KB |
#include "sorting.h" #include <algorithm> #include <cassert> #include <iostream> using namespace std; const int MN = 200005; int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { //cin >> N; for (int i=0; i<N; ++i) cin >> S[i]; if (is_sorted(S, S+N)) return 0; int K = 0; if (X[0] == 0 && Y[0] == 0) { for (int i=0; i<N; ++i) { int idx = min_element(S+i, S+N) - S; assert(i <= idx && idx < N); if (idx == i) continue; P[K] = i; Q[K] = idx; ++K; swap(S[i], S[idx]); } } else if (X[0] == 0 && Y[0] == 1) { for (int i=2; i<N; ++i) { int idx = min_element(S+i, S+N) - S; assert(i <= idx && idx < N); if (idx == i) continue; swap(S[0], S[1]); //for (int j=0; j<N; ++j) { cerr << S[j] << ' '; } cerr << endl; swap(S[i], S[idx]); P[K] = i; Q[K] = idx; ++K; //for (int j=0; j<N; ++j) { cerr << S[j] << ' '; } cerr << endl; } while (N > 2 && S[0] + S[1] > 1) { swap(S[0], S[1]); //for (int j=0; j<N; ++j) { cerr << S[j] << ' '; } cerr << endl; if (S[0] < S[1]) { P[K] = 1; swap(S[1], S[2]); } else { P[K] = 0; swap(S[0], S[2]); } Q[K] = 2; ++K; //for (int j=0; j<N; ++j) { cerr << S[j] << ' '; } cerr << endl; for (int i=2; i+1<N; ++i) { if (S[i] > S[i+1]) { swap(S[0], S[1]); //for (int j=0; j<N; ++j) { cerr << S[j] << ' '; } cerr << endl; swap(S[i], S[i+1]); P[K] = i; Q[K] = i+1; ++K; //for (int j=0; j<N; ++j) { cerr << S[j] << ' '; } cerr << endl; } else break; } } if (S[0] == 1) { assert(S[1] == 0); swap(S[0], S[1]); //for (int j=0; j<N; ++j) { cerr << S[j] << ' '; } cerr << endl; P[K] = 0; Q[K] = 0; ++K; //for (int j=0; j<N; ++j) { cerr << S[j] << ' '; } cerr << endl; } } else assert(0); //for (int i=0; i<N; ++i) { cerr << S[i] << ' '; } cerr << endl; assert(is_sorted(S, S+N)); assert(K <= M); //cout << K << endl; for (int i=0; i<K; ++i) { cout << P[i] << ' ' << Q[i] << '\n'; } return K; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 2 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 500 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 2 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Incorrect | 1 ms | 364 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 2 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 500 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 2 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Incorrect | 1 ms | 364 KB | Output isn't correct |
15 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 2 ms | 620 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 2 ms | 620 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |