This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#include <bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <functional>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
#define mp make_pair
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
const lld pi = 3.14159265358979323846;
ll calc(int n,int k,int l,int pos[],int pref){
ll cost = 0;
int last = 0;
// clockwise
for(int i = 0;i<pref;i++){
if((i+1)%k == 0){
cost += min(pos[i],l-pos[i]) + pos[i]-last;
last = 0;
}else{
cost += pos[i]-last;
last = pos[i];
}
}
if(pref%k!=0) cost += min(pos[pref-1],l-pos[pref-1]);
//cout << cost << " ";
//int before = cost;
// counterclockwise
last = l;
for(int i = n-1;i>=pref;i--){
if((n-i)%k == 0){
cost += min(pos[i],l-pos[i])+last-pos[i];
last = l;
}else{
// auf addieren
cost += last-pos[i];
last = pos[i];
}
}
if((n-pref)%k!=0) cost += min(pos[pref],l-pos[pref]);
//cout << cost-before << " ";
return cost;
}
ll delivery(int n,int k,int l,int pos[]){
ll ans = 1e18;
for(int i = 0;i<=n;i++){
ans = min(ans,calc(n,k,l,pos,i));
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |