제출 #302286

#제출 시각아이디문제언어결과실행 시간메모리
302286square1001정렬하기 (IOI15_sorting)C++14
20 / 100
1038 ms384 KiB
#include "sorting.h" #include <random> #include <vector> #include <iostream> #include <algorithm> using namespace std; mt19937 mt(2009190008); int rand_rng(int l, int r) { uniform_int_distribution<int> p(l, r - 1); return p(mt); } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { fill(P, P + M, 0); fill(Q, Q + M, 0); for(int i = 0; i < M; ++i) { if(is_sorted(S, S + N)) { return i; } swap(S[X[i]], S[Y[i]]); if(is_sorted(S, S + N)) { return i + 1; } vector<int> col(N, -1); for(int j = 0; j < N; ++j) { if(col[j] != -1) continue; int pos = j; while(col[pos] == -1) { col[pos] = j; pos = S[pos]; } } do { P[i] = rand_rng(0, N); Q[i] = rand_rng(0, N); } while(P[i] == Q[i] || col[P[i]] != col[Q[i]]); swap(S[P[i]], S[Q[i]]); } if(is_sorted(S, S + N)) { return M; } return -1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...