QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#303021#2733. Rainfall CaptureCamillus5 6ms3796kbC++201.5kb2024-01-11 16:56:512024-01-11 16:56:51

Judging History

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

  • [2024-01-11 16:56:51]
  • 评测
  • 测评结果:5
  • 用时:6ms
  • 内存:3796kb
  • [2024-01-11 16:56:51]
  • 提交

answer

#include "bits/stdc++.h"

using ll = long long;
using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    auto cost = [&]() -> int {
        vector<int> left(n, -1);
        vector<int> right(n, -1);

        vector<int> Q;

        for (int i = 0; i < n; i++) {
            while (!Q.empty() && a[Q.back()] <= a[i]) {
                Q.pop_back();
            }

            if (!Q.empty()) {
                left[i] = Q.back();
            }

            Q.push_back(i);
        }

        Q.clear();

        for (int i = n - 1; i >= 0; i--) {
            while (!Q.empty() && a[Q.back()] < a[i]) {
                Q.pop_back();
            }

            if (!Q.empty()) {
                right[i] = Q.back();
            }

            Q.push_back(i);
        }

        int sum = 0;

        for (int i = 0; i < n; i++) {
            if (left[i] != -1 && right[i] != -1 && a[right[i]] != a[i]) {
                sum += (right[i] - left[i] - 1) * (min(a[right[i]], a[left[i]]) - a[i]);
            }
        }

        return sum;
    };

    set<int> Q;

    sort(a.begin(), a.end());

    do {
        Q.insert(cost());
    } while (next_permutation(a.begin(), a.end()));

    for (int x : Q) {
        cout << x << ' ';
    }
    cout << '\n';
    return 0;
}

详细

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 0ms
memory: 3516kb

input:

2
1 50

output:

0 

result:

ok single line: '0 '

Test #2:

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

input:

10
50 50 1 1 1 1 1 1 1 1

output:

0 49 98 147 196 245 294 343 392 

result:

ok single line: '0 49 98 147 196 245 294 343 392 '

Test #3:

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

input:

10
50 50 2 2 2 1 2 1 2 2

output:

0 1 2 48 49 50 96 97 98 144 145 146 192 193 194 240 241 242 288 289 290 337 338 386 

result:

ok single line: '0 1 2 48 49 50 96 97 98 144 14...41 242 288 289 290 337 338 386 '

Test #4:

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

input:

10
50 50 3 2 3 3 3 2 3 2

output:

0 1 2 3 47 48 49 50 94 95 96 97 141 142 143 144 188 189 190 191 235 236 237 238 283 284 285 331 332 379 

result:

ok single line: '0 1 2 3 47 48 49 50 94 95 96 9...37 238 283 284 285 331 332 379 '

Test #5:

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

input:

8
16 33 33 16 33 33 33 16

output:

0 17 34 51 

result:

ok single line: '0 17 34 51 '

Test #6:

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

input:

9
14 45 14 50 34 24 34 14 34

output:

0 10 11 20 21 22 30 31 32 33 40 41 42 43 50 51 52 53 54 60 61 62 63 64 70 71 72 73 74 81 82 83 84 85 92 93 94 95 103 104 105 114 115 116 125 126 136 147 

result:

ok single line: '0 10 11 20 21 22 30 31 32 33 4...05 114 115 116 125 126 136 147 '

Test #7:

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

input:

6
17 17 4 17 17 17

output:

0 13 

result:

ok single line: '0 13 '

Test #8:

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

input:

7
36 50 50 40 43 50 40

output:

0 3 4 6 7 10 11 13 14 17 20 21 24 27 31 34 41 

result:

ok single line: '0 3 4 6 7 10 11 13 14 17 20 21 24 27 31 34 41 '

Test #9:

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

input:

8
37 10 10 37 37 10 10 37

output:

0 27 54 81 108 

result:

ok single line: '0 27 54 81 108 '

Test #10:

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

input:

7
24 17 4 24 4 4 24

output:

0 7 13 20 26 27 33 39 40 46 47 53 60 67 

result:

ok single line: '0 7 13 20 26 27 33 39 40 46 47 53 60 67 '

Test #11:

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

input:

8
21 21 17 18 47 47 18 50

output:

0 1 3 4 6 7 10 26 27 29 30 32 33 36 52 53 55 56 58 59 62 81 82 84 85 88 110 111 114 140 

result:

ok single line: '0 1 3 4 6 7 10 26 27 29 30 32 ...81 82 84 85 88 110 111 114 140 '

Test #12:

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

input:

7
9 9 23 9 23 9 9

output:

0 14 28 42 56 70 

result:

ok single line: '0 14 28 42 56 70 '

Test #13:

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

input:

8
49 7 7 49 7 49 7 7

output:

0 42 84 126 168 210 

result:

ok single line: '0 42 84 126 168 210 '

Test #14:

score: 0
Accepted
time: 6ms
memory: 3508kb

input:

10
18 35 41 41 18 3 35 18 18 3

output:

0 6 12 15 17 21 23 27 29 30 32 34 35 36 38 40 42 44 46 47 49 50 51 52 53 55 57 58 59 61 63 64 65 66 67 68 69 70 72 73 74 75 76 78 80 81 82 83 84 86 87 88 89 90 92 93 95 96 98 99 100 101 104 105 106 107 110 111 112 113 115 116 118 119 121 122 124 127 128 130 132 133 134 136 138 139 142 144 145 150 15...

result:

ok single line: '0 6 12 15 17 21 23 27 29 30 32...50 151 156 157 162 168 174 180 '

Test #15:

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

input:

9
7 47 47 29 7 47 7 47 47

output:

0 18 22 40 44 58 62 66 80 84 98 102 120 138 

result:

ok single line: '0 18 22 40 44 58 62 66 80 84 98 102 120 138 '

Test #16:

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

input:

8
31 31 31 31 21 31 31 21

output:

0 10 20 

result:

ok single line: '0 10 20 '

Test #17:

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

input:

9
35 38 48 35 35 48 18 30 30

output:

0 3 5 6 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 61 62 63 64 65 66 67 69 71 72 74 75 76 77 79 82 84 85 87 89 92 95 97 102 105 115 

result:

ok single line: '0 3 5 6 8 9 10 11 12 13 14 15 ... 85 87 89 92 95 97 102 105 115 '

Test #18:

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

input:

4
43 43 43 39

output:

0 4 

result:

ok single line: '0 4 '

Test #19:

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

input:

7
15 28 8 46 40 8 28

output:

0 7 12 13 14 19 20 24 25 26 27 31 32 33 37 38 39 40 44 45 49 51 52 53 56 57 63 64 65 69 76 77 81 88 89 101 113 

result:

ok single line: '0 7 12 13 14 19 20 24 25 26 27...4 65 69 76 77 81 88 89 101 113 '

Test #20:

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

input:

6
37 3 3 22 35 3

output:

0 13 19 32 38 45 51 57 64 70 77 83 96 109 

result:

ok single line: '0 13 19 32 38 45 51 57 64 70 77 83 96 109 '

Subtask #2:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Test #21:

score: 10
Accepted
time: 1ms
memory: 3752kb

input:

50
50 50 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

output:

0 49 98 147 196 245 294 343 392 441 490 539 588 637 686 735 784 833 882 931 980 1029 1078 1127 1176 1225 1274 1323 1372 1421 1470 1519 1568 1617 1666 1715 1764 1813 1862 1911 1960 2009 2058 2107 2156 2205 2254 2303 2352 

result:

ok single line: '0 49 98 147 196 245 294 343 39... 2107 2156 2205 2254 2303 2352 '

Test #22:

score: -10
Time Limit Exceeded

input:

50
50 50 1 2 1 1 1 1 2 2 1 1 1 1 2 2 2 2 2 1 1 1 2 1 1 1 2 1 2 2 2 1 2 1 1 2 2 1 1 1 2 2 2 1 2 1 1 2 1 2

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%