1 solutions
-
0
C++ :
#include<bits/stdc++.h> using namespace std; using LL=long long; using PLL=pair<LL,LL>; const LL INF=0x3f3f3f3f3f3f3f3f; const double EPS=1e-10; const int N=1e5+10; LL x[N], y[N]; void solve() { LL n; cin>>n; for (LL i=1; i<=n; i++) { cin>>x[i]>>y[i]; } LL totalDistance=0; for (LL i=2; i<=n; i++) { LL dis=abs(x[i-1]-x[i])+abs(y[i-1]-y[i]); totalDistance+=dis; } LL largestSkip = 0; for (LL i=2; i<n; i++) { LL noSkipDistance=abs(x[i+1]-x[i])+abs(x[i]-x[i-1])+abs(y[i+1]-y[i])+abs(y[i]-y[i-1]); LL skipDistance=abs(x[i+1]-x[i-1])+abs(y[i+1]-y[i-1]); largestSkip=max(largestSkip,noSkipDistance-skipDistance); } cout<<totalDistance - largestSkip<<"\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie (0); //freopen("marathon.in", "r", stdin); //freopen("marathon.out", "w", stdout); int T=1; //cin>>T; for (int i=1; i<=T; i++) { //cout<<i<<"\n"; solve(); } return 0; }
- 1
Information
- ID
- 1301
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 10
- Tags
- (None)
- # Submissions
- 1
- Accepted
- 1
- Uploaded By