# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
140477 | 2019-08-03T08:14:34 Z | PedroBigMan | Sorting (IOI15_sorting) | C++14 | 10 ms | 508 KB |
#include "sorting.h" #include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <string> using namespace std; typedef int ll; typedef unsigned long long int ull; typedef long double ld; #define REP(i,a,b) for(ll i=a; i<b; i++) #define pb push_back #define mp make_pair #define pl pair<ll,ll> #define ff first #define ss second #define INF ((ll) pow(2,63) -1) ll insig; #define In(vecBRO, LENBRO) REP(IBRO,0,LENBRO) {cin>>insig; vecBRO.pb(insig);} void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;} int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { ll c1, c2; vector<ll> pos, oc; REP(i,0,N) {pos.pb(i);oc.pb(0);} REP(i,0,N) {oc[S[i]]=i;} ll last=0; REP(i,0,M) { c1=pos[X[i]]; c2=pos[Y[i]]; pos[X[i]]=c2; pos[Y[i]]=c1; } vector<ll> m; REP(i,0,N) {m.pb(0);} REP(i,0,N) {m[pos[i]]=i;} ll sP=0; REP(i,0,INF) { bool srt = true; REP(i,0,N-1) {if(S[i]>S[i+1]) {srt=false;}} if(srt) {return sP;} //swap cells X[i],Y[i] because of E oc[S[X[i]]]=Y[i]; oc[S[Y[i]]]=X[i]; c1=S[X[i]]; c2=S[Y[i]]; S[X[i]]=c2; S[Y[i]]=c1; c1=pos[m[X[i]]]; c2=pos[m[Y[i]]]; pos[m[X[i]]]=c2; pos[m[Y[i]]]=c1; c1=m[X[i]]; c2=m[Y[i]]; m[X[i]]=c2; m[Y[i]]=c1; //if i<N swap cells oc[i],pos[i] because of A if(i<N) { P[i] = oc[i]; Q[i] = pos[i]; oc[S[P[i]]] = Q[i]; oc[S[Q[i]]] = P[i]; c1=S[P[i]]; c2=S[Q[i]]; S[P[i]]=c2; S[Q[i]]=c1; } else {P[sP]=0; Q[sP]=0;} sP++; } } /*int main() { ll N,M; cin>>N>>M; int S[N]; REP(i,0,N) {cin>>S[i];} int X[M],Y[M]; REP(i,0,M) {cin>>X[i]>>Y[i];} int P[M], Q[M]; cout<<findSwapPairs(N,S,M,X,Y,P,Q)<<endl; }*/
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 256 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 |
7 | Incorrect | 2 ms | 256 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 256 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 |
7 | Incorrect | 2 ms | 256 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Incorrect | 2 ms | 256 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 256 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 |
7 | Incorrect | 2 ms | 256 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 10 ms | 508 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 10 ms | 508 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |