結果

問題 No.1965 Heavier
ユーザー karinohitokarinohito
提出日時 2022-06-05 16:18:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,555 bytes
コンパイル時間 3,289 ms
コンパイル使用メモリ 203,428 KB
実行使用メモリ 6,388 KB
最終ジャッジ日時 2023-10-21 03:12:40
合計ジャッジ時間 4,466 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 45 ms
6,388 KB
testcase_07 AC 45 ms
6,388 KB
testcase_08 AC 43 ms
6,388 KB
testcase_09 AC 46 ms
6,388 KB
testcase_10 AC 46 ms
6,388 KB
testcase_11 AC 46 ms
6,388 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 45 ms
6,388 KB
testcase_16 AC 45 ms
6,388 KB
testcase_17 AC 32 ms
5,332 KB
testcase_18 AC 44 ms
6,388 KB
testcase_19 AC 43 ms
6,124 KB
testcase_20 AC 45 ms
6,388 KB
testcase_21 AC 40 ms
6,124 KB
testcase_22 AC 40 ms
5,860 KB
testcase_23 AC 28 ms
5,068 KB
testcase_24 AC 35 ms
5,596 KB
testcase_25 AC 43 ms
6,388 KB
testcase_26 AC 41 ms
6,388 KB
testcase_27 AC 46 ms
6,388 KB
testcase_28 AC 46 ms
6,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
using pqr = priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>;

template<class T>
bool chmax(T& p, T q) {
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}
template<class T>
bool chmin(T& p, T q) {
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

ll gcd(ll(a), ll(b)) {
    ll c = a;
    while (a % b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}
ll mod = 1e9 + 7;
ll modPow(long long a, long long n, long long p = mod) {
    if (n == 0) return 1; // 0乗にも対応する場合
    if (n == 1) return a % p;
    if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
    ll t = modPow(a, n / 2, p);
    return (t * t) % p;
}



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

    ll N;
    cin>>N;
    vll A(N),B(N);
    rep(i,N)cin>>A[i];
    rep(i,N)cin>>B[i];

    ll k=0;
    ll an=0;
    rep(i,N-1){
        ll M=max(B[i],B[i+1]);
        ll m=min(B[i],B[i+1]);
        if(m+A[i+1]>M+A[i]){
            k++;
        }
        else{
            an+=k*(k+1)/2;
            k=0;
        }
    }
    cout<<an+(k*(k+1))/2<<endl;
}
0