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 "boxes.h"
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pii pair <int, int>
#define pb push_back
#define F first
#define S second
#define ll long long
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define M_PI 3.14159265358979323846
const int N = 200005;
const int mod = 1e9 + 7;
vector<int> a[N];
int used[N], m, o, z;
ll ans = 0, res = LONG_MAX;
void DFS(int node, int rem, int vis){
used[node] = 1;
ll cur = ans;
if(vis == z){
ans += min(node, m - node);
res = min(res, ans);
}
else{
ans += min(node, m - node);
if(node != m) DFS(m, o, vis);
if(rem == 0) {
ans = cur;
used[node] = 0;
return;
}
for(int i : a[node]){
if(!used[i]){
ans = cur + min(abs(node - i), m - abs(node - i));
DFS(i, rem - 1, vis + 1);
}
}
}
ans = cur;
used[node] = 0;
}
long long delivery(int n, int k, int l, int p[]) {
if(k == 1){
ll ans = 0;
for(int i = 0; i < n; i++){
ans += min(p[i], l - p[i]);
}
return ans * 2;
}
if(k == n){
ll ans = min(l, (min(p[n - 1] * 2, (l - p[0]) * 2)));
for(int i = 1; i < n; i++){
ll cur = (p[i - 1] * 2 + (l - p[i]) * 2);
ans = min(ans, cur);
}
return ans;
}
m = l;
o = k;
z = n;
for(int i = 0; i < n; i++){
a[m].pb(p[i]);
for(int j = i + 1; j < n; j++){
int x = p[i];
int y = p[j];
a[x].pb(y);
a[y].pb(x);
}
}
DFS(m, k, 0);
return res;
}
Compilation message (stderr)
boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:49:12: warning: declaration of 'ans' shadows a global declaration [-Wshadow]
49 | ll ans = 0;
| ^~~
boxes.cpp:19:4: note: shadowed declaration is here
19 | ll ans = 0, res = LONG_MAX;
| ^~~
boxes.cpp:56:12: warning: declaration of 'ans' shadows a global declaration [-Wshadow]
56 | ll ans = min(l, (min(p[n - 1] * 2, (l - p[0]) * 2)));
| ^~~
boxes.cpp:19:4: note: shadowed declaration is here
19 | ll ans = 0, res = LONG_MAX;
| ^~~
# | 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... |