Submission #3607598
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;
vector<int> a;
int n, max1, max2, min1, min2, cost;
int main()
{
cin>>n;
a.push_back(0);
REP(i,n) {
int tmp;
cin>>tmp;
a.push_back(tmp);
}
a.push_back(0);
REP(i,n+1) {
cost += abs(a[i+1] - a[i]);
}
REP(i,n) {
int pd = abs(a[i+1] - a[i]) + abs(a[i+2] - a[i+1]);
int cd = abs(a[i+2] - a[i]);
if (pd == cd) {
cout<<cost<<endl;
} else {
cout<<cost - pd + cd<<endl;
}
}
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Traveling Plan |
User |
Cmer |
Language |
C++14 (GCC 5.4.1) |
Score |
300 |
Code Size |
1052 Byte |
Status |
AC |
Exec Time |
186 ms |
Memory |
1784 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
300 / 300 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample-01.txt, sample-02.txt, sample-03.txt |
All |
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 |
AC |
186 ms |
1784 KB |
02.txt |
AC |
183 ms |
1784 KB |
03.txt |
AC |
1 ms |
256 KB |
04.txt |
AC |
186 ms |
1784 KB |
05.txt |
AC |
182 ms |
1784 KB |
06.txt |
AC |
183 ms |
1784 KB |
07.txt |
AC |
182 ms |
1784 KB |
08.txt |
AC |
182 ms |
1784 KB |
09.txt |
AC |
177 ms |
1400 KB |
10.txt |
AC |
178 ms |
1400 KB |
11.txt |
AC |
175 ms |
1400 KB |
12.txt |
AC |
177 ms |
1400 KB |
sample-01.txt |
AC |
1 ms |
256 KB |
sample-02.txt |
AC |
1 ms |
256 KB |
sample-03.txt |
AC |
1 ms |
256 KB |