結果

問題 No.999 てん vs. ほむ
ユーザー outlineoutline
提出日時 2020-02-28 21:33:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,559 bytes
コンパイル時間 1,081 ms
コンパイル使用メモリ 107,436 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-21 17:58:45
合計ジャッジ時間 2,433 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
5,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 21 ms
5,376 KB
testcase_18 AC 21 ms
5,376 KB
testcase_19 AC 21 ms
5,376 KB
testcase_20 AC 21 ms
5,376 KB
testcase_21 AC 29 ms
5,376 KB
testcase_22 AC 28 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const int mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    cin >> n;
    int sz = n * 2;
    vector<ll> a(sz);
    for(int i = 0; i < sz; ++i)    cin >> a[i];
    
    int left = 0, right = sz - 1;
    ll res = 0;
    int remain = sz;
    while(remain > 2){
        ll foo = a[left] - a[left + 1];
        ll bar = a[right] - a[right - 1];
        if(foo >= bar){
            res += foo;
            left = left + 2;
        }
        else{
            res += bar;
            right = right - 2;
        }
        remain -= 2;
    }
    if(remain % 2 == 0){
        ll foo = a[left] - a[right];
        ll bar = a[right] - a[left];
        res += max(foo, bar);
    }
    else{
        res += a[left];
    }
    cout << res << endl;
}
0