結果

問題 No.1965 Heavier
ユーザー mnmmnm
提出日時 2022-06-03 22:15:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,036 bytes
コンパイル時間 1,596 ms
コンパイル使用メモリ 76,216 KB
実行使用メモリ 14,060 KB
最終ジャッジ日時 2023-10-21 01:58:16
合計ジャッジ時間 5,192 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
14,060 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,348 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:42:22: warning: 'right' may be used uninitialized [-Wmaybe-uninitialized]
   42 |             cnt+=add(right-i);
      |                      ^~~~~
main.cpp:29:15: note: 'right' was declared here
   29 |     int left, right;
      |               ^~~~~

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

#define rep(i,n) for(i=0; i<n; ++i)
#define in(a) cin >> a
#define out(a,b) cout << a << b
using namespace std;
using lint = long long;

lint add(lint n){
    if(n==0)    return 0;
    else    return add(n-1) + n;
}

int main(void){
    lint i, j, n, m, k, cnt = 0;
    in(n);
    vector<lint> A(n);
    vector<lint> B(n);
    rep(i,n)    in(A[i]);
    rep(i,n)    in(B[i]);
    vector<lint> dis_A(n-1);
    vector<lint> dis_B(n-1);
    rep(i,n-2)  dis_A[i]=A[i+1]-A[i];
    rep(i,n-2)  dis_B[i]=abs(B[i+1]-B[i]);
    int left, right;
    i = 0;
    while(i<n-1){
        if(dis_B[i]<dis_A[i]){
            j=i;
            while(j<n-1){
                j++;
                if(dis_B[j]>dis_A[j]){
                    break;
                }
                right = j;
            }
            // cout << right;
            cnt+=add(right-i);
            i=j+1;
        }
        else        i++;
    }
    out(cnt,endl);
    return 0;
}

0