QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#558061#3967. Meticulous smoothingLaVuna47AC ✓6ms4016kbC++172.4kb2024-09-11 13:56:232024-09-11 13:56:23

Judging History

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

  • [2024-09-11 13:56:23]
  • 评测
  • 测评结果:AC
  • 用时:6ms
  • 内存:4016kb
  • [2024-09-11 13:56:23]
  • 提交

answer

/** gnu specific **/
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/** contains everything I need in std **/
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(S) ((int)S.size())
#define FOR(i, n) for(int i = 0; i < n; ++i)
#define RFOR(i, n) for(int i = n-1; i >= 0; --i)
#define output_vec(vec) { FOR(i_, sz(vec)) cout << vec[i_] << ' '; cout << '\n'; }
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<bool> vb;
typedef short si;
typedef unsigned long long ull;
typedef long double LD;
typedef pair<ull, ull> pull;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
using namespace std;
#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int n;

ll get_ans(vector<ll>& a)
{
    ll ans = 0;
    FOR(i, n-1)
    {
        if(a[i] > a[i+1])
        {
            if(a[i] - a[i+1] > 1)
            {
                ll delta = a[i]-a[i+1]-1;
                ans += delta;
                a[i] -= delta;
            }
        }
        else
        {
            if(a[i+1] - a[i] > 1)
            {
                ll delta = a[i+1]-a[i]-1;
                ans += delta;
                a[i+1] -= delta;
            }
        }
    }
    return ans;
}

bool is_smooth(const vector<ll>& a)
{
    FOR(i, n-1)
    {
        if(abs(a[i]-a[i+1]) > 1)
            return false;
    }
    return true;
}

int solve()
{
    if (!(cin >> n))
        return 1;
        
    vector<ll> a(n);

    FOR (i, n) cin >> a[i];
    ll ans = get_ans(a);
    reverse(all(a));
    ans += get_ans(a);
    assert(is_smooth(a));

    cout << ans << '\n';
    return 0;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int TET = 1;
    //cin >> TET;
    for (int i = 1; i <= TET; i++)
    {
        if (solve())
        {
            break;
        }
#ifdef ONPC
        cout << "__________________________" << endl;
#endif
    }
#ifdef ONPC
    cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3744kb

input:

5
1 6 7 2 5

output:

10

result:

ok single line: '10'

Test #2:

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

input:

19
9 37 5 17 8 32 29 31 25 14 7 32 2 25 28 1 29 18 15

output:

275

result:

ok single line: '275'

Test #3:

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

input:

19
1 1 1 3 2 3 3 5 2 5 1 5 2 4 4 5 3 5 4

output:

12

result:

ok single line: '12'

Test #4:

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

input:

19
37 37 37 37 34 37 37 37 37 37 37 37 37 37 37 37 37 37 37

output:

6

result:

ok single line: '6'

Test #5:

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

input:

19
1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 817623 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 377745 1000000

output:

11018059

result:

ok single line: '11018059'

Test #6:

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

input:

19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

output:

0

result:

ok single line: '0'

Test #7:

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

input:

19
19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1

output:

0

result:

ok single line: '0'

Test #8:

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

input:

19
1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 10

output:

16

result:

ok single line: '16'

Test #9:

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

input:

19
19 18 17 16 15 14 13 12 11 19 18 17 16 15 14 13 12 11 10

output:

16

result:

ok single line: '16'

Test #10:

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

input:

19
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38

output:

171

result:

ok single line: '171'

Test #11:

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

input:

19
38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2

output:

171

result:

ok single line: '171'

Test #12:

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

input:

19
2 4 6 8 10 12 14 16 18 2 4 6 8 10 12 14 16 18 20

output:

97

result:

ok single line: '97'

Test #13:

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

input:

19
38 36 34 32 30 28 26 24 22 38 36 34 32 30 28 26 24 22 20

output:

93

result:

ok single line: '93'

Test #14:

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

input:

19
1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1

output:

8999982

result:

ok single line: '8999982'

Test #15:

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

input:

19
1 645796 1 791891 1 552717 1 258931 1 770842 1 305153 1 76154 1 471589 1 489285 1

output:

4362340

result:

ok single line: '4362340'

Test #16:

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

input:

100000
54783 3056 136661 192936 9484 41423 62640 4426 14405 178612 38601 182132 96284 62840 30705 88626 122246 185649 93255 73553 102833 69027 90267 59929 54098 93106 82149 58561 80122 190480 134053 110223 60657 151297 119417 110068 128352 20699 120877 148031 94363 115161 149322 82617 181935 169233 ...

output:

9959715601

result:

ok single line: '9959715601'

Test #17:

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

input:

100000
3 4 4 3 4 2 4 1 4 3 2 2 1 3 3 3 2 5 3 1 2 5 3 1 2 5 1 4 4 5 3 2 3 3 3 4 1 3 4 4 5 2 5 3 5 1 3 1 1 5 3 2 4 2 3 3 3 4 4 1 2 4 1 4 4 1 4 1 4 5 1 4 1 2 2 4 3 1 5 1 4 5 3 4 5 1 2 3 1 1 5 1 2 1 4 1 1 1 4 2 3 2 2 5 1 2 5 2 1 1 2 3 4 4 1 4 4 4 4 3 1 1 1 2 4 3 5 4 1 2 1 4 1 3 1 4 4 2 4 2 2 2 4 4 5 2 4...

output:

71923

result:

ok single line: '71923'

Test #18:

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

input:

100000
199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999 199999...

output:

6725041808

result:

ok single line: '6725041808'

Test #19:

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

input:

100000
1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 10000...

output:

79453958554

result:

ok single line: '79453958554'

Test #20:

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

input:

100000
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 100 1...

output:

0

result:

ok single line: '0'

Test #21:

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

input:

100000
100000 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 9995...

output:

0

result:

ok single line: '0'

Test #22:

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

input:

100000
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 100 1...

output:

624975000

result:

ok single line: '624975000'

Test #23:

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

input:

100000
100000 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 9995...

output:

624975000

result:

ok single line: '624975000'

Test #24:

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

input:

100000
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 17...

output:

4999950000

result:

ok single line: '4999950000'

Test #25:

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

input:

100000
200000 199998 199996 199994 199992 199990 199988 199986 199984 199982 199980 199978 199976 199974 199972 199970 199968 199966 199964 199962 199960 199958 199956 199954 199952 199950 199948 199946 199944 199942 199940 199938 199936 199934 199932 199930 199928 199926 199924 199922 199920 199918...

output:

4999950000

result:

ok single line: '4999950000'

Test #26:

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

input:

100000
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 17...

output:

3124925000

result:

ok single line: '3124925000'

Test #27:

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

input:

100000
200000 199998 199996 199994 199992 199990 199988 199986 199984 199982 199980 199978 199976 199974 199972 199970 199968 199966 199964 199962 199960 199958 199956 199954 199952 199950 199948 199946 199944 199942 199940 199938 199936 199934 199932 199930 199928 199926 199924 199922 199920 199918...

output:

3124925000

result:

ok single line: '3124925000'

Test #28:

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

input:

100000
1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1...

output:

49999900000

result:

ok single line: '49999900000'

Test #29:

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

input:

100000
1 778415 1 572162 1 746683 1 237405 1 668923 1 800753 1 221168 1 151327 1 170786 1 137471 1 196699 1 29147 1 251540 1 99600 1 941498 1 730363 1 135726 1 947913 1 531055 1 724120 1 694386 1 283837 1 243851 1 712465 1 137810 1 13877 1 808508 1 663790 1 272749 1 545618 1 954114 1 292458 1 129834...

output:

24959210219

result:

ok single line: '24959210219'

Test #30:

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

input:

5
1 2 1 2 1

output:

0

result:

ok single line: '0'

Test #31:

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

input:

5
102 1 102 1 102

output:

300

result:

ok single line: '300'

Test #32:

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

input:

1
10

output:

0

result:

ok single line: '0'

Test #33:

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

input:

5
1 2 3 4 5

output:

0

result:

ok single line: '0'

Test #34:

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

input:

5
2 4 6 8 10

output:

10

result:

ok single line: '10'

Test #35:

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

input:

5
9 8 7 6 5

output:

0

result:

ok single line: '0'

Test #36:

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

input:

5
10 8 6 4 2

output:

10

result:

ok single line: '10'