Submission #9634818
Source Code Expand
#include<stdio.h> #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <ctime> using namespace std; //conversion //------------------------------------------ inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} //math //------------------------------------------- template<class T> inline T sqr(T x) {return x*x;} //typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; //container util //------------------------------------------ #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort((c).begin(),(c).end()) //repetition //------------------------------------------ #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) //constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); //clear memory #define CLR(a) memset((a), 0 ,sizeof(a)) //debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; void solve(long long N, std::vector<long long> A){ vector<LL> costs; LL sum=0; // costs.PB(A[0]); // sum+=A[0]; for(int i=0; i < A.size()-1; i++){ costs.PB(abs(A[i]-A[i+1])); sum+=abs(A[i]-A[i+1]); } // costs.PB(abs(A[N-1])); //back in 0 // sum+=A[N-1]; for(int i=1; i<=N; i++){ int ans=sum; ans=sum-costs[i-1]-costs[i] + abs(A[i-1]-A[i+1]); cout<<ans<<endl; } } int main(){ long long N; cin>>N; // scanf("%lld",&N); std::vector<long long> A; // for(int i = 0 ; i < N ; i++){ // scanf("%lld",&A[i]); // } A.PB(0); for(int i = 0 ; i < N ; i++){ LL v; cin>>v; A.PB(v); } A.PB(0); solve(N, std::move(A)); return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Traveling Plan |
User | jojojoe77 |
Language | C++14 (GCC 5.4.1) |
Score | 300 |
Code Size | 2678 Byte |
Status | AC |
Exec Time | 184 ms |
Memory | 2932 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 | 182 ms | 2932 KB |
02.txt | AC | 181 ms | 2932 KB |
03.txt | AC | 1 ms | 256 KB |
04.txt | AC | 181 ms | 2932 KB |
05.txt | AC | 184 ms | 2932 KB |
06.txt | AC | 181 ms | 2932 KB |
07.txt | AC | 182 ms | 2932 KB |
08.txt | AC | 180 ms | 2932 KB |
09.txt | AC | 176 ms | 2676 KB |
10.txt | AC | 176 ms | 2676 KB |
11.txt | AC | 176 ms | 2676 KB |
12.txt | AC | 178 ms | 2676 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 |