結果

問題 No.999 てん vs. ほむ
ユーザー ugis_progugis_prog
提出日時 2020-02-28 22:36:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,112 bytes
コンパイル時間 1,768 ms
コンパイル使用メモリ 170,852 KB
実行使用メモリ 6,728 KB
最終ジャッジ日時 2023-08-03 21:20:18
合計ジャッジ時間 3,944 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
4,376 KB
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 AC 54 ms
6,488 KB
testcase_18 AC 53 ms
6,368 KB
testcase_19 AC 53 ms
6,444 KB
testcase_20 AC 53 ms
6,440 KB
testcase_21 AC 77 ms
6,448 KB
testcase_22 AC 75 ms
6,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

i64 f(int& N, deque<i64> dq){
    i64 tem = 0, hom = 0;
    rep(i, N){
        size_t sz = dq.size(); 
        if(dq[0] - dq[1] >= dq[sz - 1] - dq[sz - 2]){
            hom += dq[0];
            tem += dq[1];
            rep(i, 2) dq.pop_front();
        } else {
            hom += dq[sz - 1];
            tem += dq[sz - 2];
            rep(i, 2) dq.pop_back();
        }
    }
    return hom - tem;
}

i64 g(int& N, deque<i64> dq){
    i64 tem = 0, hom = 0;
    rep(i, N){
        size_t sz = dq.size(); 
        if(dq[1] <= dq[sz - 2]){
            hom += dq[0];
            tem += dq[1];
            rep(i, 2) dq.pop_front();
        } else {
            hom += dq[sz - 1];
            tem += dq[sz - 2];
            rep(i, 2) dq.pop_back();
        }
    }
    return hom - tem;
}

int main(){
    int N;
    cin >> N;
    deque<i64> dq(2*N);
    rep(i, 2*N) cin >> dq[i];

    cout << max(f(N, dq), g(N, dq)) << endl;
}
0