# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
140563 | 2019-08-03T14:10:31 Z | SirCeness | Sorting (IOI15_sorting) | C++14 | 355 ms | 22328 KB |
#include "sorting.h" #include <bits/stdc++.h> #define pb push_back #define mp make_pair #define inside sl<=l&&r<=sr #define outside r<sl||sr<l #define orta ((l+r)>>1) #define INF 1000000009 #define mod 1000000007 #define ppair(x) "(" << x.first << ", " << x.second << ") " #define bas(x) #x << ": " << x << " " #define prarr(x, n); cerr << #x << ": "; for(int qsd = 0; qsd < n; qsd++) cerr << x[qsd] << " "; cerr << "\n"; #define prarrv(x); cerr << #x << ": "; for(int qsd = 0; qsd < (int)x.size(); qsd++) cerr << x[qsd] << " "; cerr << "\n"; using namespace std; typedef long long ll; int n, m; int dene(int N, int S[], int M, int X[], int Y[], int P[], int Q[]){ n = N; m = M; vector<int> sanal; for (int i = 0; i < n; i++) sanal.pb(S[i]); for (int i = 0; i < m; i++) swap(sanal[X[i]], sanal[Y[i]]); vector<int> sim; for (int i = 0; i < n; i++) sim.pb(S[i]); //prarrv(sanal); vector<int> yer(n); for (int i = 0; i < n; i++) yer[sanal[i]] = i; vector<pair<int, int> > deg; for (int i = 0; i < n; i++){ if (sanal[i] != i){ int j = yer[i]; yer[sanal[i]] = j; deg.pb(mp(sanal[i], sanal[j])); swap(sanal[i], sanal[j]); } } //for (int i = 0; i < deg.size(); i++) cout << ppair(deg[i]) << " "; cout << endl; int r = deg.size(); if (r > m) return 0; return 1; } void yap(int N, int S[], int M, int X[], int Y[], int P[], int Q[]){ n = N; m = M; vector<int> sanal; for (int i = 0; i < n; i++) sanal.pb(S[i]); for (int i = 0; i < m; i++) swap(sanal[X[i]], sanal[Y[i]]); vector<int> sim; for (int i = 0; i < n; i++) sim.pb(S[i]); //prarrv(sanal); vector<int> yer(n); for (int i = 0; i < n; i++) yer[sanal[i]] = i; vector<pair<int, int> > deg; for (int i = 0; i < n; i++){ if (sanal[i] != i){ int j = yer[i]; yer[sanal[i]] = j; deg.pb(mp(sanal[i], sanal[j])); swap(sanal[i], sanal[j]); } } //for (int i = 0; i < deg.size(); i++) cout << ppair(deg[i]) << " "; cout << endl; int r = deg.size(); //if (r > m) return 0; for (int i = 0; i < n; i++) yer[S[i]] = i; for (int i = 0; i < M; i++){ yer[S[X[i]]] = Y[i]; yer[S[Y[i]]] = X[i]; swap(S[X[i]], S[Y[i]]); if (i >= r){ P[i] = 0; Q[i] = 0; continue; } P[i] = yer[deg[i].first]; Q[i] = yer[deg[i].second]; yer[S[P[i]]] = Q[i]; yer[S[Q[i]]] = P[i]; swap(S[P[i]], S[Q[i]]); } /*prarrv(sim); for (int i = 0; i < m; i++){ swap(sim[X[i]], sim[Y[i]]); prarrv(sim); swap(sim[P[i]], sim[Q[i]]); prarrv(sim); }*/ //return 1; } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { int l = 0; int r = M; while (l < r){ int mid = (l+r)/2; if (dene(N, S, mid, X, Y, P, Q)) r = mid; else l = mid+1; } yap(N, S, l, X, Y, P, Q); return l; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Correct | 2 ms | 256 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 252 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Correct | 2 ms | 256 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 2 ms | 256 KB | Output is correct |
14 | Correct | 2 ms | 252 KB | Output is correct |
15 | Correct | 2 ms | 376 KB | Output is correct |
16 | Correct | 2 ms | 376 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 2 ms | 256 KB | Output is correct |
19 | Correct | 2 ms | 256 KB | Output is correct |
20 | Correct | 2 ms | 256 KB | Output is correct |
21 | Correct | 3 ms | 376 KB | Output is correct |
22 | Correct | 3 ms | 376 KB | Output is correct |
23 | Correct | 3 ms | 376 KB | Output is correct |
24 | Correct | 3 ms | 380 KB | Output is correct |
25 | Correct | 3 ms | 376 KB | Output is correct |
26 | Correct | 3 ms | 376 KB | Output is correct |
27 | Correct | 3 ms | 504 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 504 KB | Output is correct |
2 | Correct | 3 ms | 504 KB | Output is correct |
3 | Correct | 3 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 504 KB | Output is correct |
5 | Correct | 3 ms | 508 KB | Output is correct |
6 | Correct | 3 ms | 376 KB | Output is correct |
7 | Correct | 3 ms | 376 KB | Output is correct |
8 | Correct | 3 ms | 504 KB | Output is correct |
9 | Correct | 3 ms | 504 KB | Output is correct |
10 | Correct | 3 ms | 504 KB | Output is correct |
11 | Correct | 3 ms | 504 KB | Output is correct |
12 | Correct | 3 ms | 376 KB | Output is correct |
13 | Correct | 3 ms | 504 KB | Output is correct |
14 | Correct | 3 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 504 KB | Output is correct |
2 | Correct | 3 ms | 504 KB | Output is correct |
3 | Correct | 3 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 504 KB | Output is correct |
5 | Correct | 3 ms | 508 KB | Output is correct |
6 | Correct | 3 ms | 376 KB | Output is correct |
7 | Correct | 3 ms | 376 KB | Output is correct |
8 | Correct | 3 ms | 504 KB | Output is correct |
9 | Correct | 3 ms | 504 KB | Output is correct |
10 | Correct | 3 ms | 504 KB | Output is correct |
11 | Correct | 3 ms | 504 KB | Output is correct |
12 | Correct | 3 ms | 376 KB | Output is correct |
13 | Correct | 3 ms | 504 KB | Output is correct |
14 | Correct | 3 ms | 376 KB | Output is correct |
15 | Correct | 285 ms | 12108 KB | Output is correct |
16 | Correct | 300 ms | 20336 KB | Output is correct |
17 | Correct | 335 ms | 21364 KB | Output is correct |
18 | Correct | 119 ms | 18708 KB | Output is correct |
19 | Correct | 255 ms | 19904 KB | Output is correct |
20 | Correct | 268 ms | 20196 KB | Output is correct |
21 | Correct | 276 ms | 20320 KB | Output is correct |
22 | Correct | 294 ms | 16432 KB | Output is correct |
23 | Correct | 329 ms | 22108 KB | Output is correct |
24 | Correct | 355 ms | 21736 KB | Output is correct |
25 | Correct | 345 ms | 21584 KB | Output is correct |
26 | Correct | 256 ms | 19852 KB | Output is correct |
27 | Correct | 236 ms | 18988 KB | Output is correct |
28 | Correct | 326 ms | 21416 KB | Output is correct |
29 | Correct | 317 ms | 21092 KB | Output is correct |
30 | Correct | 192 ms | 18144 KB | Output is correct |
31 | Correct | 325 ms | 21796 KB | Output is correct |
32 | Correct | 310 ms | 21244 KB | Output is correct |
33 | Correct | 352 ms | 21664 KB | Output is correct |
34 | Correct | 334 ms | 21600 KB | Output is correct |
35 | Correct | 254 ms | 19448 KB | Output is correct |
36 | Correct | 117 ms | 17008 KB | Output is correct |
37 | Correct | 347 ms | 22328 KB | Output is correct |
38 | Correct | 334 ms | 21416 KB | Output is correct |
39 | Correct | 337 ms | 21460 KB | Output is correct |