結果

問題 No.1077 Noelちゃんと星々4
ユーザー udonmanudonman
提出日時 2020-06-12 23:00:48
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,132 bytes
コンパイル時間 627 ms
コンパイル使用メモリ 85,956 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-06 11:09:46
合計ジャッジ時間 1,764 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
4,380 KB
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int mx6[] = {1,0,-1,1,-1,0};
int my6[] = {1,1,1,0,0,-1};

int main() {
    int n; cin >> n;
    vector<ll> y(n+2),Y(n+2);
    rep(i,n) {
        cin >> y[i+1];
        Y[i+1] = y[i+1];
    }

    ll ans = 0;
    Y[n+1] = y[n];
  	y[n+1] = y[n];
    rep(i,n){
        if(y[i] <= y[i+1]) continue;
        else{
            if(y[i-1] <= y[i+1]){
                if(abs(y[i]-y[i+1])<abs(y[i]-y[i-1])) {
                    y[i] = y[i+1];
                }else{
                    y[i] = y[i-1];
                }
            }else{
                y[i+1] = y[i];
            }
        }
    }
    
    rep(i,n+1){
        ans+=abs(Y[i]-y[i]);
    }
    cout << ans << endl;

//rep(i,n+1) cout << y[i] << " ";
}
0