結果

問題 No.999 てん vs. ほむ
ユーザー wonda_t_coffeewonda_t_coffee
提出日時 2020-02-28 21:53:00
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,153 bytes
コンパイル時間 773 ms
コンパイル使用メモリ 80,788 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 18:23:26
合計ジャッジ時間 2,050 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define REP(i,n)  for (int i = 0; i < (n); ++i)
#define SORT(a)   sort((a).begin(), (a).end());
#define UNIQ(a)   SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define FIND(a,x) find((a).begin(), (a).end(), (x)) != (a).end()

using namespace std;
using ll = long long;
using P = pair<int,int>;
using namespace std;

const int MOD = 1000000007; // 10^9 + 7

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

  int N; cin >> N;
  vector<ll> a(2 * N);
  REP(i, 2 * N) cin >> a[i];

  ll ans = 0;
  ll l = 0, r = 2 * N - 1;
  REP(i, N) {
    ll h1 = a[l], h2 = a[l + 1];

    ll len = r - l + 1;
    if (len == 2) {
      ans += abs(a[l] - a[r]);
    } else {
      ll t1 = a[r], t2 = a[r - 1];
      if (h1 - h2 > t1 - t2) {
        ans += h1 - h2;
        l += 2;
      } else {
        ans += t1 - t2;
        r -= 2;
      }
    }
  }
  cout << ans << endl;
}
0