Submission #4571189


Source Code Expand

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

long long n;
vector<long long> a;
long long sum[100005] = {0};

void solve();

int main() {
  cin >> n;
  a.assign(n + 2, 0);
  for(int i = 1; i <= n; ++i) cin >> a[i];
  solve();
  return 0;
}

void solve() {
  for(int i = 1; i < n + 2; ++i) {
    sum[i] = sum[i - 1];
    sum[i] += abs(a[i] - a[i - 1]);
  }
  for(int i = 1; i <= n; ++i) {
    long long now = 0;
    now += sum[i - 1] + sum[n + 1];
    now -= sum[i + 1];
    now += abs(a[i - 1] - a[i + 1]);
    cout << now << endl;
  }
}

Submission Info

Submission Time
Task C - Traveling Plan
User m_tsubasa
Language C++14 (GCC 5.4.1)
Score 300
Code Size 567 Byte
Status
Exec Time 186 ms
Memory 2816 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample-01.txt, sample-02.txt, sample-03.txt
All 300 / 300 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, sample-01.txt, sample-02.txt, sample-03.txt
Case Name Status Exec Time Memory
01.txt 182 ms 2816 KB
02.txt 182 ms 2816 KB
03.txt 1 ms 256 KB
04.txt 186 ms 2816 KB
05.txt 181 ms 2816 KB
06.txt 181 ms 2816 KB
07.txt 180 ms 2816 KB
08.txt 179 ms 2816 KB
09.txt 175 ms 2432 KB
10.txt 173 ms 2432 KB
11.txt 177 ms 2432 KB
12.txt 173 ms 2432 KB
sample-01.txt 1 ms 256 KB
sample-02.txt 1 ms 256 KB
sample-03.txt 1 ms 256 KB