# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
594577 | 2022-07-12T17:13:05 Z | davi_bart | 정렬하기 (IOI15_sorting) | C++14 | 44 ms | 440 KB |
#pragma GCC optimize("O3") #include <bits/stdc++.h> #include "sorting.h" using namespace std; #define ll long long // #define int ll #define fi first #define se second #define ld long double #define pb push_back mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int N; struct Dsu { vector<int> par, dim; Dsu(vector<int> &k) { par.resize(N); dim = vector<int>(N, 1); iota(par.begin(), par.end(), 0); for (int i = 0; i < k.size(); i++) { unite(i, k[i]); } } int find(int pos) { return par[pos] = par[pos] == pos ? pos : find(par[pos]); } void unite(int a, int b) { a = find(a); b = find(b); if (a == b) return; if (dim[a] < dim[b]) swap(a, b); par[b] = a; dim[a] += dim[b]; } int conta() { int tot = 0; for (int i = 0; i < N; i++) { if (i == par[i]) tot += dim[i] - 1; } return tot; } }; vector<int> v; vector<int> ini; int findSwapPairs(int N, int S[], int M, int P[], int Q[], int X[], int Y[]) { ::N = N; for (int i = 0; i < N; i++) v.pb(S[i]); ini = v; int ans = 0; for (int i = 0; i < M; i++) { Dsu dsu(v); // cout << dsu.conta() << " "; if (dsu.conta() <= i) { ans = i; break; } swap(v[P[i]], v[Q[i]]); } cout << endl; int o = 0; while (1) { int k = o; for (int i = 0; i < N; i++) { if (v[i] != i) { X[o] = i; Y[o++] = v[i]; swap(v[i], i); } } if (k == o) break; } return ans; v = ini; multiset<int> ok; vector<bool> valid; for (int i = 0; i < ans; i++) { Dsu dsu(v); if (dsu.find(P[i]) == dsu.find(Q[i])) { swap(v[P[i]], v[Q[i]]); ok.insert(P[i]); ok.insert(Q[i]); valid.pb(1); } else valid.pb(0); cout << valid[i] << endl; } for (int i = 0; i < ans; i++) { if (valid[i]) { swap(v[P[i]], v[Q[i]]); ok.erase(ok.find(P[i])); ok.erase(ok.find(Q[i])); for (int j = 0; j < N; j++) { if (v[j] != j && ok.count(j) == 0) { X[i] = j; Y[i] = v[j]; swap(v[j], v[v[j]]); break; } } } else { X[i] = P[i]; Y[i] = Q[i]; } } return ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 308 KB | Output is correct |
3 | Correct | 1 ms | 312 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Incorrect | 0 ms | 304 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 308 KB | Output is correct |
3 | Correct | 1 ms | 312 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Incorrect | 0 ms | 304 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Incorrect | 1 ms | 212 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 308 KB | Output is correct |
3 | Correct | 1 ms | 312 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Incorrect | 0 ms | 304 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 44 ms | 440 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 44 ms | 440 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |