結果
| 問題 |
No.999 てん vs. ほむ
|
| コンテスト | |
| ユーザー |
wonda_t_coffee
|
| 提出日時 | 2020-02-28 21:53:00 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,153 bytes |
| コンパイル時間 | 727 ms |
| コンパイル使用メモリ | 80,412 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 17:18:49 |
| 合計ジャッジ時間 | 1,935 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 WA * 12 |
ソースコード
#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;
}
wonda_t_coffee