Submission #3602658
Source Code Expand
#include <bits/stdc++.h> #define pc(x) putchar_unlocked(x); typedef int64_t int64; using namespace std; inline void fastscan(int &num) { bool neg = false; int c; num = 0; c = getchar(); if (c == '-') { neg = true; c = getchar(); } for (; (c > 47 && c < 58); c = getchar()) num = num * 10 + c - 48; if (neg) num *= -1; } inline void fastout(int n) { int N = n, rev, count = 0; rev = N; if (N == 0) { pc('0'); pc('\n'); return ;} while ((rev % 10) == 0) { count++; rev /= 10;} rev = 0; while (N != 0) { rev = (rev<<3) + (rev<<1) + N % 10; N /= 10;} while (rev != 0) { pc(rev % 10 + '0'); rev /= 10;} while (count--) pc('0'); } int main(){ ios::sync_with_stdio(false); cin.tie(0); int N; fastscan(N); int v[N]; for (int i = 0; i < N; ++i) fastscan(v[i]); int sum = 0; for (int i = 1; i < N; ++i) sum += abs(v[i - 1] - v[i]); sum = sum + abs(0 - v[0]) + abs(v[N - 1] - 0); int diff[N]; diff[0] = abs(0 - v[0]) + abs(v[0] - v[1]) - abs(0 - v[1]); for (int i = 1; i < N - 1; ++i){ diff[i] = abs(v[i - 1] - v[i]) + abs(v[i] - v[i + 1]) - abs(v[i - 1] - v[i + 1]); } diff[N - 1] = abs(v[N - 2] - v[N - 1]) + abs(v[N - 1] - 0) - abs(v[N - 2] - 0); for (int i = 0; i < N; ++i){ fastout(sum - diff[i]); pc('\n'); } return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Traveling Plan |
User | kyomukyomupurin |
Language | C++14 (GCC 5.4.1) |
Score | 300 |
Code Size | 1438 Byte |
Status | AC |
Exec Time | 13 ms |
Memory | 2048 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 | 13 ms | 2048 KB |
02.txt | AC | 13 ms | 2048 KB |
03.txt | AC | 1 ms | 256 KB |
04.txt | AC | 13 ms | 2048 KB |
05.txt | AC | 13 ms | 2048 KB |
06.txt | AC | 13 ms | 2048 KB |
07.txt | AC | 13 ms | 2048 KB |
08.txt | AC | 13 ms | 2048 KB |
09.txt | AC | 10 ms | 1664 KB |
10.txt | AC | 9 ms | 1664 KB |
11.txt | AC | 9 ms | 1664 KB |
12.txt | AC | 9 ms | 1792 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 |