QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#151574#2789. SortingAbdelmagedNour#20 30ms22224kbC++201009b2023-08-27 01:45:582024-07-04 02:41:21

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 02:41:21]
  • 评测
  • 测评结果:20
  • 用时:30ms
  • 内存:22224kb
  • [2023-08-27 01:45:58]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
//#include "grader.cpp"
#include "sorting.h"
bool check(int T,int N,int M,int S[],int X[],int Y[],int P[],int Q[]){
    vector<vector<int>>nxt(T+1,vector<int>(N));
    for(int i=0;i<N;i++)nxt[T][i]=i;
    for(int i=T-1;i>=0;i--){
        for(int j=0;j<N;j++){
            nxt[i][j]=nxt[i+1][j];
        }
        swap(nxt[i][X[i]],nxt[i][Y[i]]);
    }
    int a[N];
    for(int i=0;i<N;i++)a[i]=S[i];
    for(int i=0;i<T;i++){
        int j=0;
        swap(a[X[i]],a[Y[i]]);
        while(j<N&&a[j]==nxt[i+1][j])j++;
        if(j==N)P[i]=Q[i]=0;
        else P[i]=j,Q[i]=find(nxt[i+1].begin(),nxt[i+1].end(),a[j])-nxt[i+1].begin();
        swap(a[P[i]],a[Q[i]]);
    }
    return is_sorted(a,a+N);
}
int findSwapPairs(int N,int S[],int M,int X[],int Y[],int P[],int Q[]){
    int l=1,r=M,res=1;
    while(l<=r){
        int md=(l+r)>>1;
        if(check(md,N,M,S,X,Y,P,Q))r=(res=md)-1;
        else l=md+1;
    }
    return res;
}

详细

Subtask #1:

score: 8
Accepted

Test #1:

score: 8
Accepted
time: 0ms
memory: 4072kb

input:

1
0
1
0 0

output:

1
0 0

result:

ok correct

Test #2:

score: 0
Accepted
time: 0ms
memory: 3796kb

input:

2
0 1
4
0 0
0 0
0 0
0 0

output:

1
0 0

result:

ok correct

Test #3:

score: 0
Accepted
time: 0ms
memory: 3708kb

input:

2
1 0
4
0 0
0 0
0 0
0 0

output:

1
0 1

result:

ok correct

Test #4:

score: 0
Accepted
time: 0ms
memory: 3704kb

input:

3
1 0 2
9
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

output:

1
0 1

result:

ok correct

Test #5:

score: 0
Accepted
time: 0ms
memory: 3788kb

input:

4
3 2 0 1
16
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

output:

3
0 3
0 1
0 2

result:

ok correct

Test #6:

score: 0
Accepted
time: 0ms
memory: 3796kb

input:

5
1 4 2 3 0
25
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

output:

2
0 1
0 4

result:

ok correct

Test #7:

score: 0
Accepted
time: 0ms
memory: 3728kb

input:

5
4 2 1 0 3
25
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

output:

3
0 4
0 3
1 2

result:

ok correct

Subtask #2:

score: 12
Accepted

Test #8:

score: 12
Accepted
time: 0ms
memory: 3656kb

input:

1
0
30
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

output:

1
0 0

result:

ok correct

Test #9:

score: 0
Accepted
time: 0ms
memory: 3668kb

input:

2
0 1
60
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

output:

1
0 0

result:

ok correct

Test #10:

score: 0
Accepted
time: 1ms
memory: 3916kb

input:

98
82 70 31 12 27 51 84 90 66 8 49 52 74 91 46 7 96 67 63 85 34 50 87 83 58 78 26 39 77 48 2 55 94 25 61 56 53 13 32 86 72 20 37 73 9 93 65 28 18 11 71 59 88 35 76 40 24 36 33 3 17 29 38 5 21 15 79 30 62 92 45 80 64 95 43 75 97 23 16 57 22 60 41 69 0 42 14 10 47 68 19 4 1 6 44 81 54 89
2940
0 0
0 0
...

output:

93
0 82
0 41
0 20
0 34
0 61
0 29
0 48
0 18
0 63
0 5
0 51
0 59
0 3
0 12
0 74
0 43
0 73
0 95
0 81
0 60
0 17
0 67
0 30
0 2
0 31
0 55
0 40
0 72
0 64
0 21
0 50
0 71
0 80
0 22
0 87
0 10
0 49
0 11
0 52
0 88
0 47
0 28
0 77
0 23
0 83
0 69
0 92
0 1
0 70
0 45
0 93
0 6
0 84
4 27
4 39
4 86
4 14
4 46
4 65
4 15
4 ...

result:

ok correct

Test #11:

score: 0
Accepted
time: 1ms
memory: 3940kb

input:

99
8 14 3 0 98 74 18 10 50 93 49 23 80 2 54 79 90 31 66 38 81 36 42 83 39 7 9 71 59 62 67 4 68 5 70 72 34 95 25 27 45 61 97 48 29 15 46 12 87 22 26 63 77 84 11 85 30 24 40 78 41 1 96 69 94 19 6 65 33 13 52 75 88 82 86 20 92 43 89 47 28 73 35 32 53 60 21 16 37 58 44 76 57 56 17 55 91 51 64
2970
0 0
0...

output:

92
0 8
0 50
0 26
0 9
0 93
0 56
0 30
0 67
0 65
0 19
0 38
0 25
0 7
0 10
0 49
0 22
0 42
0 97
0 51
0 63
0 69
0 13
0 2
0 3
1 14
1 54
1 11
1 23
1 83
1 32
1 68
1 33
1 5
1 74
1 86
1 21
1 36
1 34
1 70
1 52
1 77
1 43
1 48
1 87
1 16
1 90
1 44
1 29
1 62
1 96
1 91
1 76
1 92
1 57
1 24
1 39
1 27
1 71
1 75
1 20
1 8...

result:

ok correct

Test #12:

score: 0
Accepted
time: 1ms
memory: 3908kb

input:

96
12 91 75 59 44 30 52 63 41 13 93 79 82 60 85 78 50 53 57 8 80 67 34 24 87 17 47 33 83 21 81 40 89 49 32 70 26 9 43 7 11 37 94 36 23 28 90 42 35 25 62 56 20 84 55 45 46 22 77 51 0 69 1 31 54 2 3 58 88 76 5 6 65 92 39 66 15 95 10 27 14 86 72 4 68 18 38 19 64 73 71 74 48 29 61 16
2880
0 0
0 0
0 0
0 ...

output:

95
0 12
0 82
0 72
0 65
0 2
0 75
0 66
0 3
0 59
0 51
0 56
0 46
0 90
0 71
0 6
0 52
0 20
0 80
0 14
0 85
0 18
0 57
0 22
0 34
0 32
0 89
0 73
0 92
0 48
0 35
0 70
0 5
0 30
0 81
0 86
0 38
0 43
0 36
0 26
0 47
0 42
0 94
0 61
0 69
0 76
0 15
0 78
0 10
0 93
0 29
0 21
0 67
0 58
0 77
0 95
0 16
0 50
0 62
0 1
0 91
0 ...

result:

ok correct

Subtask #3:

score: 0
Wrong Answer

Test #13:

score: 16
Accepted
time: 0ms
memory: 3796kb

input:

2
0 1
60
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1

output:

1
0 1

result:

ok correct

Test #14:

score: 0
Accepted
time: 0ms
memory: 3796kb

input:

5
0 4 1 3 2
150
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
...

output:

2
0 4
1 2

result:

ok correct

Test #15:

score: 0
Accepted
time: 1ms
memory: 4000kb

input:

96
7 15 12 95 11 50 20 42 81 29 58 80 56 71 63 66 44 6 64 39 2 22 73 1 24 27 69 28 45 25 60 61 5 94 14 65 9 86 68 32 79 37 3 57 34 35 10 88 76 78 21 93 19 53 84 52 4 33 38 55 62 67 77 41 31 48 91 49 51 43 90 8 87 54 16 17 70 46 85 0 75 92 74 47 36 89 30 13 59 26 40 18 82 83 72 23
2880
0 1
0 1
0 1
0 ...

output:

91
0 15
0 7
0 66
0 42
0 91
0 3
0 18
0 95
0 64
0 23
0 31
1 61
0 67
1 49
0 78
1 85
0 89
1 26
0 69
1 43
0 57
1 33
0 94
1 72
0 87
1 13
0 71
1 8
0 81
1 92
0 82
1 74
0 16
1 44
0 34
1 14
0 63
1 41
0 37
1 86
0 30
1 60
0 62
1 77
0 46
1 10
0 58
1 38
0 68
1 51
0 93
1 83
0 47
1 88
0 59
1 55
0 52
1 19
0 39
1 32
...

result:

ok correct

Test #16:

score: -16
Wrong Answer
time: 1ms
memory: 3864kb

input:

99
28 2 16 95 73 6 30 90 18 46 82 69 59 4 40 49 33 29 66 86 97 56 22 96 38 35 67 15 83 44 36 72 81 41 76 47 34 87 65 9 92 57 0 55 68 5 32 17 61 50 14 19 58 24 98 48 53 60 45 12 39 3 8 74 88 77 13 85 84 42 79 51 94 70 10 25 75 31 62 27 64 1 80 78 21 37 7 63 52 23 71 20 54 26 43 91 89 93 11
2970
0 1
0...

output:

92
0 2
0 28
0 16
0 83
0 33
0 78
0 41
0 62
0 57
0 8
0 60
0 18
0 39
0 66
0 9
0 13
0 46
0 4
0 32
0 73
0 81
0 70
0 1
1 79
0 27
1 15
0 49
1 50
0 14
1 40
0 92
1 54
0 98
1 11
0 69
1 42
3 95
3 91
3 20
3 97
3 93
3 26
3 67
3 85
3 37
3 87
3 63
3 74
3 10
3 82
3 80
3 64
3 88
3 52
3 58
3 45
3 5
3 6
3 30
3 36
3 34...

result:

wrong answer the final array is not sorted

Subtask #4:

score: 0
Skipped

Dependency #2:

100%
Accepted

Dependency #3:

0%

Subtask #5:

score: 0
Wrong Answer

Test #28:

score: 0
Wrong Answer
time: 30ms
memory: 22224kb

input:

1800
530 1775 466 953 230 1179 944 752 990 1316 275 1029 158 152 1673 1706 172 115 599 1661 131 699 1112 454 551 1059 291 495 28 67 773 480 839 462 1210 757 879 285 439 3 1429 820 26 1023 942 199 356 625 1705 1421 144 1529 716 7 1485 1027 1599 696 517 1353 456 1389 273 1363 1414 1177 718 41 777 1621...

output:

1794
0 530
0 288
0 1704
0 346
0 1543
0 941
0 475
0 576
0 965
0 1091
0 194
0 1005
0 1734
0 1664
0 139
0 1736
0 1406
0 713
0 1157
0 1310
0 1342
0 1323
0 1671
0 1156
0 1727
0 486
0 633
0 513
0 1499
0 104
0 1712
0 492
0 1480
0 282
0 512
0 910
0 491
0 863
0 1015
0 980
0 1198
0 192
0 212
0 880
0 508
0 651...

result:

wrong answer the final array is not sorted

Subtask #6:

score: 0
Skipped

Dependency #5:

0%