Submission #31820

# Submission time Handle Problem Language Result Execution time Memory
31820 2017-09-10T12:45:59 Z top34051 Sorting (IOI15_sorting) C++14
74 / 100
47 ms 10288 KB
#include "sorting.h"
#include<bits/stdc++.h>
using namespace std;
#define maxn 2005

int n, s[maxn];
int a[maxn], pos[maxn];
pair<int,int> sw[maxn];

int get(int rec) {
    int i,x,cnt;
    for(i=0;i<n;i++) a[i] = s[i];
    for(i=0;i<n;i++) pos[a[i]] = i;
    cnt = 0;
    for(i=0;i<n;i++) {
        x = pos[i];
        if(i!=x) {
            pos[a[i]] = x;
            swap(a[i], a[x]);
            if(rec) sw[cnt] = {a[i],a[x]};
            cnt++;
        }
    }
    return cnt;
}

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    int i,x,now;
    n = N;
    for(i=0;i<n;i++) s[i] = S[i];
    for(now=-1;now<M;now++) {
        if(now>=0) swap(s[X[now]],s[Y[now]]);
        if(get(0)<=now+1) break;
    }
    get(1);
    for(i=0;i<n;i++) s[i] = S[i];
    for(i=0;i<now+1;i++) {
        swap(s[X[i]], s[Y[i]]);
//        printf("i = %d : {%d, %d}\n",i,sw[i].first,sw[i].second);
        for(x=0;x<n;x++) {
            if(s[x]==sw[i].first) P[i] = x;
            if(s[x]==sw[i].second) Q[i] = x;
        }
        swap(s[P[i]], s[Q[i]]);
    }
    return now+1;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 256 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 256 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 304 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 6 ms 512 KB Output is correct
22 Correct 4 ms 512 KB Output is correct
23 Correct 5 ms 512 KB Output is correct
24 Correct 4 ms 512 KB Output is correct
25 Correct 4 ms 512 KB Output is correct
26 Correct 4 ms 512 KB Output is correct
27 Correct 4 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 384 KB Output is correct
2 Correct 19 ms 384 KB Output is correct
3 Correct 18 ms 512 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 14 ms 384 KB Output is correct
8 Correct 18 ms 512 KB Output is correct
9 Correct 26 ms 512 KB Output is correct
10 Correct 21 ms 384 KB Output is correct
11 Correct 21 ms 384 KB Output is correct
12 Correct 15 ms 384 KB Output is correct
13 Correct 24 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 384 KB Output is correct
2 Correct 19 ms 384 KB Output is correct
3 Correct 18 ms 512 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 14 ms 384 KB Output is correct
8 Correct 18 ms 512 KB Output is correct
9 Correct 26 ms 512 KB Output is correct
10 Correct 21 ms 384 KB Output is correct
11 Correct 21 ms 384 KB Output is correct
12 Correct 15 ms 384 KB Output is correct
13 Correct 24 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Runtime error 47 ms 10288 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Halted 0 ms 0 KB -