結果

問題 No.838 Noelちゃんと星々3
ユーザー RubikunRubikun
提出日時 2019-06-14 22:49:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 783 bytes
コンパイル時間 1,804 ms
コンパイル使用メモリ 169,868 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 18:03:31
合計ジャッジ時間 3,049 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007;

int main(){
   
    int N;cin>>N;
    vector<ll> S(N);
    vector<bool> T(N,0);
    for(int i=0;i<N;i++){
        cin>>S[i];
    }
    sort(all(S));
    ll sum=0;
    for(int i=0;i<N;i++){
        if(i==0){
            sum+=S[1]-S[0];
            S[0]=S[1];
        }else if(i!=N-1){
            if(S[i]==S[i-1]) continue;
            else if(S[i]==S[i+1]) continue;
            else if(S[i]-S[i-1]<S[i+1]-S[i]){
                sum+=S[i]-S[i-1];
                S[i]=S[i-1];
            }else{
                sum+=S[i+1]-S[i];
                S[i]=S[i+1];
            }
        }else sum+=S[i]-S[i-1];
        
    }
    cout<<sum<<endl;
        }
0