結果

問題 No.2648 [Cherry 6th Tune D] 一次元の馬
コンテスト
ユーザー vjudge1
提出日時 2026-11-22 18:00:11
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 20 ms / 2,000 ms
+ 981µs
コード長 3,099 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,480 ms
コンパイル使用メモリ 353,800 KB
実行使用メモリ 9,868 KB
最終ジャッジ日時 2026-11-22 18:00:20
合計ジャッジ時間 7,346 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<ll>;

#define int long long
#define f first
#define s second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define foo(i,a,b) for (int i = (a); i < (b); ++i)
#define rfoo(i,a,b) for (int i = (a); i >= (b); --i)
#define input(v) for (auto &x : v) cin >> x
#define print(v) { for (auto x : v) cout << x << " "; cout << '\n'; }
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define nl cout << "\n";


const int MOD = 1e9 + 7;
const ll INF = 1e18;

#define fastio ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

// ll gcd(ll a, ll b) {
//     return std::gcd(a, b);
// }

ll power(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1) res *= a;
        a *= a;
        b >>= 1;
    }
    return res;
}

ll modexp(ll a, ll b, ll mod = MOD) {
    ll res = 1;
    a = (a % mod + mod) % mod;

    while (b > 0) {
        if (b & 1) res = (__int128)res * a % mod;
        a = (__int128)a * a % mod;
        b >>= 1;
    }
    return res;
}

bool isprime(ll n) {
    if (n < 2) return false;

    for (ll i = 2; i <= n / i; ++i) {
        if (n % i == 0) return false;
    }
    return true;
}

void sieve(int n, vector<bool> &isPrime) {
    if (n < 0) {
        isPrime.clear();
        return;
    }
    isPrime.assign(n + 1, true);
    isPrime[0] = false;

    if (n >= 1) isPrime[1] = false;

    for (int i = 2; i <= n / i; ++i) {
        if (isPrime[i]) {
            for (ll j = 1LL * i * i; j <= n; j += i) {
                isPrime[j] = false;
            }
        }
    }
}

bool ispoftwo(ll n) {
    return n > 0 && !(n & (n - 1));
}

int countSetBits(ll n) {
    return __builtin_popcountll(n);
}

int digitCount(ll n, int base = 10) {
    if (base <= 1) return -1;

    unsigned long long x = n < 0
        ? 0ULL - (unsigned long long)n
        : (unsigned long long)n;

    if (x == 0) return 1;

    int cnt = 0;
    while (x > 0) {
        cnt++;
        x /= base;
    }
    return cnt;
}


vll factors(ll n) {
    vll res;

    if (n <= 0) return res;

    for (ll i = 1; i <= n / i; i++) {
        if (n % i == 0) {
            res.pb(i);
            if (i != n / i) res.pb(n / i);
        }
    }
    sort(all(res));
    return res;
}


#define count_occ(v, x) (ub(v, x) - lb(v, x))

bool already (int a, int b, int x) {
    if (x > a-b) {
        return true;
    }
    else {
        return false;
    }
}


signed main() {
    fastio;

    int t = 1;
    cin >> t;
     
    while (t--) {
       int n; cin>>n;
       vi v(n);
       input(v);

       int i = 0, j = 1;
        int min_operations = 0;

       while (j < n) {
        int a = v[i], b = v[j];

        if (!already (a,b, min_operations)) {
            int extra_needed = a - b + 1 - min_operations;
            min_operations += extra_needed;
        }

        i++;
        j++;
       }
       cout<<min_operations;
       nl
    }

      
    return 0;
}
0