QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#506270#1191. Reordering the Documentsarnold518#AC ✓93ms200084kbC++172.3kb2024-08-05 16:19:482024-08-05 16:19:48

Judging History

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

  • [2024-08-05 16:19:48]
  • 评测
  • 测评结果:AC
  • 用时:93ms
  • 内存:200084kb
  • [2024-08-05 16:19:48]
  • 提交

answer

#include <bits/stdc++.h>
#define ff first
#define ss second;
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 5000;

const int MOD = 1e9+7;
struct mint
{
    int x;
    mint() : x(0) {}
    mint(int _x) : x(_x) {}
    mint operator + (int ot) const { return x+ot>=MOD ? x+ot-MOD : x+ot; }
    mint operator - (int ot) const { return x<ot ? x+MOD-ot : x-ot; }
    mint operator * (int ot) const { return 1ll * x * ot % MOD; }
    mint operator += (int ot) { return *this = *this + ot; }
    mint operator -= (int ot) { return *this = *this - ot; }
    mint operator *= (int ot) { return *this = *this * ot; }
    operator int() const { return x; }
};

int N, K, A[MAXN+10];
mint dp1[MAXN+10][MAXN+10], dp2[MAXN+10][MAXN+10];

mint f2(int i, int s, int l, int r)
{
    if(l>r) return 0;
    return dp2[r][i-s]-(l>0 ? dp2[l-1][i-s] : mint(0));
}

mint f1(int i, int s, int l, int r)
{
    if(l>r) return 0;
    return dp1[r][s]-(l>0 ? dp1[l-1][s] : mint(0));
}

int main() {
    cin.tie(0); ios_base::sync_with_stdio(0);

    scanf("%d%d", &N, &K);
    for(int i=1; i<=N; i++) scanf("%d", &A[i]);

    A[0]=0; A[N+1]=N+1;

    dp1[0][0]=dp2[0][0]=1;

    mint ans;
    for(int i=1; i<=N; i++)
    {
        int l=i, r=i, p;
        for(; r<N && A[r]<A[r+1]; r++);
        for(; l>1 && A[l-1]<A[l]; l--);
        for(p=l; p<=r && A[p]<A[i+1]; p++);
        p--;

        for(int s=0; s<=i; s++)
        {
            mint val1, val2;
            if(A[i]<A[i+1])
            {
                val1+=f2(i, s, l, i-1);
                if(A[l-1]<A[i+1]) val1+=f2(i, s, l-1, l-1);

                val2+=f1(i, s, l, i-1);
                if(A[l-1]<A[i+1]) val2+=f1(i, s, l-1, l-1);
            }
            else
            {
                val1+=f2(i, s, l, p);
                val2+=f1(i, s, l, p);
                if(A[l-1]<A[i+1]) val1+=f2(i, s, l-1, l-1);
                if(A[l-1]<A[i+1]) val2+=f1(i, s, l-1, l-1);
            }

            // printf("%d %d : %d %d\n", i, s, val1.x, val2.x);

            if(i==N && N-K<=s && s<=K) ans+=val1+val2;
            dp1[i][s]=dp1[i-1][s]+val1;
            dp2[i][i-s]+=dp2[i-1][i-s]+val2;
        }
    }
    printf("%d\n", ans.x);
}

详细

Test #1:

score: 100
Accepted
time: 7ms
memory: 200068kb

input:

6 3
1 3 4 2 6 5

output:

4

result:

ok answer is '4'

Test #2:

score: 0
Accepted
time: 7ms
memory: 199984kb

input:

6 6
1 3 4 2 6 5

output:

8

result:

ok answer is '8'

Test #3:

score: 0
Accepted
time: 11ms
memory: 199980kb

input:

4 4
4 3 1 2

output:

0

result:

ok answer is '0'

Test #4:

score: 0
Accepted
time: 3ms
memory: 199992kb

input:

6 3
1 3 4 2 6 5

output:

4

result:

ok answer is '4'

Test #5:

score: 0
Accepted
time: 7ms
memory: 199976kb

input:

6 6
1 3 4 2 6 5

output:

8

result:

ok answer is '8'

Test #6:

score: 0
Accepted
time: 4ms
memory: 199980kb

input:

4 4
4 3 1 2

output:

0

result:

ok answer is '0'

Test #7:

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

input:

1000 500
4 5 6 8 10 11 12 13 14 15 20 23 25 26 28 29 33 35 1 2 36 38 3 7 41 9 16 44 48 17 18 51 52 53 19 21 54 22 24 59 61 62 27 67 30 31 32 34 68 69 37 39 73 40 76 77 42 81 83 43 85 45 87 46 89 94 47 95 49 50 97 101 55 103 105 56 57 58 106 60 108 110 63 111 114 64 115 65 119 66 70 71 120 121 72 124...

output:

11363968

result:

ok answer is '11363968'

Test #8:

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

input:

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

output:

809753703

result:

ok answer is '809753703'

Test #9:

score: 0
Accepted
time: 3ms
memory: 200008kb

input:

1000 500
1 2 4 5 6 7 8 12 13 14 17 22 23 24 27 30 31 33 34 37 38 42 45 46 47 48 49 50 51 52 54 57 58 61 63 64 66 67 68 69 76 78 79 81 82 83 84 90 91 92 93 95 97 98 3 9 10 11 15 16 99 105 18 106 108 109 19 20 21 25 26 28 113 118 123 29 32 129 133 35 134 36 39 40 135 41 137 43 142 44 143 145 147 53 55...

output:

292864

result:

ok answer is '292864'

Test #10:

score: 0
Accepted
time: 11ms
memory: 199996kb

input:

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

output:

957884317

result:

ok answer is '957884317'

Test #11:

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

input:

1000 500
2 3 4 5 7 8 9 11 14 18 21 22 23 26 28 33 35 37 38 40 41 47 49 50 51 53 54 55 59 60 61 63 64 65 66 70 73 75 77 79 80 87 88 90 95 96 99 100 101 102 103 104 108 109 110 111 114 115 116 117 121 122 126 128 1 6 10 129 130 12 132 133 13 134 135 15 141 16 142 143 17 19 20 24 145 25 27 29 30 147 14...

output:

20979531

result:

ok answer is '20979531'

Test #12:

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

input:

2000 1000
1 2 3 7 9 16 17 18 19 21 22 24 27 30 31 32 34 37 39 40 42 43 45 46 47 49 50 55 56 57 58 60 63 64 65 66 4 70 71 72 74 5 75 6 78 79 8 80 82 10 11 12 13 14 15 84 86 20 23 25 88 90 91 92 26 93 96 28 29 98 33 99 100 102 35 104 107 36 38 41 44 48 109 112 51 52 113 116 117 53 118 122 123 125 54 5...

output:

290071346

result:

ok answer is '290071346'

Test #13:

score: 0
Accepted
time: 19ms
memory: 199996kb

input:

2000 1000
2 4 6 9 10 14 16 17 20 22 23 24 27 29 31 33 35 40 42 47 48 49 51 56 59 60 62 65 67 68 70 71 74 75 78 79 82 86 93 95 96 97 98 99 100 101 102 104 105 109 111 113 115 117 118 122 123 124 125 127 130 132 133 134 135 136 137 141 142 145 147 148 154 156 158 159 160 161 169 173 175 176 178 179 18...

output:

64

result:

ok answer is '64'

Test #14:

score: 0
Accepted
time: 19ms
memory: 200004kb

input:

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

output:

235072

result:

ok answer is '235072'

Test #15:

score: 0
Accepted
time: 7ms
memory: 199912kb

input:

2000 1000
1 4 5 7 9 11 14 15 18 20 22 23 24 28 29 30 31 33 34 37 38 39 40 41 44 46 47 49 50 52 54 60 61 62 68 69 70 71 72 77 81 84 2 86 3 91 92 6 8 10 95 96 12 99 101 102 13 103 104 109 113 115 116 16 117 17 119 120 121 122 125 126 127 132 19 21 134 25 135 26 27 32 35 36 42 43 45 137 48 138 141 51 5...

output:

166912791

result:

ok answer is '166912791'

Test #16:

score: 0
Accepted
time: 11ms
memory: 200000kb

input:

2000 1000
2 3 4 5 7 8 9 11 14 18 21 22 23 26 28 33 35 37 38 40 41 47 49 50 51 53 54 55 59 60 61 63 64 65 66 70 73 75 77 79 80 87 1 6 10 12 88 13 15 16 90 17 19 95 20 96 99 24 100 101 102 25 103 104 108 109 27 29 30 110 31 32 111 114 115 116 34 117 121 36 122 126 39 42 43 128 44 129 130 45 132 133 46...

output:

418696764

result:

ok answer is '418696764'

Test #17:

score: 0
Accepted
time: 28ms
memory: 199992kb

input:

3000 1500
1 2 3 7 9 16 17 18 19 21 22 24 27 30 31 32 34 37 39 40 42 43 45 46 47 49 50 55 56 57 58 60 63 64 65 66 70 71 72 74 75 78 79 80 82 84 86 88 90 91 92 93 96 98 99 100 102 104 107 109 112 113 116 117 118 122 123 125 127 131 132 133 136 138 139 140 141 144 146 147 149 150 153 154 157 158 161 4 ...

output:

505570241

result:

ok answer is '505570241'

Test #18:

score: 0
Accepted
time: 23ms
memory: 199884kb

input:

3000 1500
2 4 6 9 10 14 16 17 20 22 23 24 27 29 31 33 35 40 42 47 48 49 51 56 59 60 62 65 67 68 70 71 74 75 78 79 82 86 93 95 96 97 98 99 100 101 102 104 105 109 111 113 115 117 118 122 123 124 125 127 130 132 133 134 135 136 137 141 142 145 147 148 154 156 158 159 160 161 169 173 175 176 178 179 18...

output:

2

result:

ok answer is '2'

Test #19:

score: 0
Accepted
time: 29ms
memory: 199920kb

input:

3000 1500
3 9 10 11 15 16 18 19 20 21 25 26 28 29 32 35 36 39 40 41 43 44 53 55 56 59 60 62 65 70 71 1 72 73 2 74 4 75 77 80 85 86 5 87 6 88 7 8 89 94 96 12 13 100 101 14 17 102 103 104 22 107 23 24 110 27 30 31 111 112 114 115 33 34 37 116 117 38 119 120 121 122 42 45 124 46 47 48 49 50 125 126 127...

output:

2024192

result:

ok answer is '2024192'

Test #20:

score: 0
Accepted
time: 19ms
memory: 199880kb

input:

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

output:

697783719

result:

ok answer is '697783719'

Test #21:

score: 0
Accepted
time: 27ms
memory: 199920kb

input:

3000 1500
2 3 4 5 7 8 9 11 14 18 21 22 23 26 28 33 35 37 38 40 41 47 49 50 51 53 54 55 59 60 1 6 61 63 64 10 12 65 13 66 15 70 16 73 75 77 17 19 79 80 20 87 24 88 90 25 27 29 30 31 32 34 95 36 96 99 100 39 101 42 102 43 44 45 103 46 48 52 104 56 57 108 58 62 67 68 109 110 111 114 115 116 69 117 71 7...

output:

721286793

result:

ok answer is '721286793'

Test #22:

score: 0
Accepted
time: 48ms
memory: 200012kb

input:

4000 2000
1 2 3 7 9 16 17 18 19 21 22 24 27 30 31 32 34 37 39 40 42 43 45 46 47 49 50 55 56 57 58 60 63 64 65 66 70 71 72 74 75 78 79 80 82 84 86 88 90 91 92 93 96 98 99 100 102 104 107 109 112 113 116 117 118 122 123 125 127 131 132 133 136 138 139 140 141 144 146 147 149 150 153 154 157 158 161 16...

output:

474181687

result:

ok answer is '474181687'

Test #23:

score: 0
Accepted
time: 32ms
memory: 200000kb

input:

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

output:

12368

result:

ok answer is '12368'

Test #24:

score: 0
Accepted
time: 31ms
memory: 200080kb

input:

4000 2000
3 9 10 11 15 16 18 19 20 21 25 26 28 29 32 35 36 39 40 41 43 44 53 55 56 59 60 62 65 70 71 72 73 74 1 2 4 75 77 80 85 5 6 7 86 87 8 88 12 89 94 13 96 14 100 101 17 102 22 103 23 24 104 107 27 110 111 30 31 33 112 34 37 38 42 45 46 47 48 49 50 114 51 52 115 54 116 117 119 57 120 121 122 124...

output:

318291867

result:

ok answer is '318291867'

Test #25:

score: 0
Accepted
time: 53ms
memory: 200020kb

input:

4000 2000
2 3 6 8 10 12 13 16 17 19 21 25 26 27 32 35 36 42 43 45 48 51 53 55 56 57 58 59 63 64 65 66 67 73 74 75 76 78 79 80 82 83 85 87 88 89 90 93 94 97 98 100 105 106 107 108 110 111 112 114 118 123 124 128 129 130 1 131 4 133 136 5 7 9 11 14 139 140 15 18 20 22 23 24 28 29 30 31 33 34 142 37 38...

output:

85518659

result:

ok answer is '85518659'

Test #26:

score: 0
Accepted
time: 32ms
memory: 199888kb

input:

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

output:

29597070

result:

ok answer is '29597070'

Test #27:

score: 0
Accepted
time: 56ms
memory: 200080kb

input:

5000 2500
1 2 3 7 9 16 17 18 19 21 22 24 27 30 31 32 34 37 39 40 42 43 45 46 47 49 50 55 56 57 58 60 63 64 65 66 70 71 72 74 75 78 79 80 82 84 86 88 90 91 92 93 96 98 99 100 102 104 107 109 112 113 116 117 118 122 123 125 127 131 132 133 136 138 139 140 141 144 146 147 149 150 153 154 157 158 161 16...

output:

398080

result:

ok answer is '398080'

Test #28:

score: 0
Accepted
time: 56ms
memory: 199916kb

input:

5000 2500
1 3 5 7 8 11 12 13 15 18 19 21 25 26 28 30 32 34 36 37 38 39 41 43 44 45 46 50 52 53 54 55 57 58 61 63 64 66 69 72 73 76 77 80 81 83 84 85 87 88 89 90 91 92 94 103 106 107 108 110 112 114 116 119 120 121 126 128 129 131 138 139 140 143 144 146 149 150 151 152 153 155 157 162 163 164 165 16...

output:

108654396

result:

ok answer is '108654396'

Test #29:

score: 0
Accepted
time: 67ms
memory: 200084kb

input:

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

output:

293975703

result:

ok answer is '293975703'

Test #30:

score: 0
Accepted
time: 52ms
memory: 200016kb

input:

5000 2500
2 3 6 8 10 12 13 16 17 19 21 25 26 27 32 35 36 42 43 45 48 51 53 55 56 57 58 59 63 64 65 66 67 73 1 4 74 75 76 78 79 80 82 5 83 85 87 88 7 9 11 14 89 90 93 15 18 94 20 22 97 98 23 100 105 24 28 29 30 31 106 33 107 108 110 34 37 38 39 40 41 44 111 112 46 114 118 47 123 49 124 128 50 129 130...

output:

961199856

result:

ok answer is '961199856'

Test #31:

score: 0
Accepted
time: 64ms
memory: 199944kb

input:

5000 2500
2 3 4 5 7 8 9 11 14 18 21 22 23 26 28 33 35 37 38 40 41 1 6 10 47 49 50 51 53 54 12 13 55 15 16 17 19 20 59 60 24 61 63 64 25 65 27 66 29 70 73 30 31 75 32 34 36 77 39 79 80 87 42 88 90 95 43 96 44 45 99 100 46 48 52 56 57 58 101 102 62 67 68 103 69 71 104 108 109 110 72 74 111 76 78 81 11...

output:

297034581

result:

ok answer is '297034581'

Test #32:

score: 0
Accepted
time: 83ms
memory: 200004kb

input:

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

output:

504674186

result:

ok answer is '504674186'

Test #33:

score: 0
Accepted
time: 93ms
memory: 199904kb

input:

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

output:

294639993

result:

ok answer is '294639993'

Test #34:

score: 0
Accepted
time: 87ms
memory: 200012kb

input:

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

output:

0

result:

ok answer is '0'

Test #35:

score: 0
Accepted
time: 92ms
memory: 199992kb

input:

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

output:

248346497

result:

ok answer is '248346497'

Test #36:

score: 0
Accepted
time: 80ms
memory: 200052kb

input:

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

output:

2

result:

ok answer is '2'

Test #37:

score: 0
Accepted
time: 92ms
memory: 199888kb

input:

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

output:

2

result:

ok answer is '2'

Test #38:

score: 0
Accepted
time: 80ms
memory: 200020kb

input:

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

output:

0

result:

ok answer is '0'

Test #39:

score: 0
Accepted
time: 84ms
memory: 200076kb

input:

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

output:

248346497

result:

ok answer is '248346497'