#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef long double lld;
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define per(i,a,b) for(ll i = a; i >= b; i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)(x).size()
#define trav(a,x) for(auto a : x)
#define inf 1000000000000000000
ll n,myL,k;
vi a;
long long find(ll h, ll v){
if ((h < 0)||(v < 0)) return inf+1;
if (h+v > n) return inf+1;
ll l = n-h-v;
ll res = ((l+k-1)/k)*myL;
ll cur = h-1;
while(cur >= 0){
res += a[cur]*2;
cur -= k;
}
cur = n-v;
while (cur < n){
res += (myL-a[cur])*2;
cur += k;
}
return res;
}
long long delivery(int N, int K, int L, int p[]) {
ll best = inf; n = N, myL = L, k = K;
rep(i,0,N) {
if (p[i] == 0) n--;
else a.push_back(p[i]);
}
ll h=n/4,v=n/4;
best = find(h,v);
lld step = lld(n);
while (ll(step) != 0){
ll dx[9] = {1,1,1,0,0,0,-1,-1,-1};
ll dy[9] = {-1,0,1,-1,0,1,-1,0,1};
ll val[9] = {0,0,0,0,0,0,0,0,0};
rep(i,0,15){
ll t = 0;
rep(i,0,9){
val[i] = find(h+dx[i]*ll(step),v+dy[i]*ll(step));
if (val[i] < val[t]) t = i;
}
if (best != val[t]) { h = h + dx[t], v = v + dy[t]; best = val[t]; }
}
step *= 0.9;
}
return best;
}
Compilation message
boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:53:11: warning: declaration of 'i' shadows a previous local [-Wshadow]
rep(i,0,9){
^
boxes.cpp:8:27: note: in definition of macro 'rep'
#define rep(i,a,b) for(ll i = a; i < b; i++)
^
boxes.cpp:51:9: note: shadowed declaration is here
rep(i,0,15){
^
boxes.cpp:8:27: note: in definition of macro 'rep'
#define rep(i,a,b) for(ll i = a; i < b; i++)
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
296 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
352 KB |
Output is correct |
2 |
Incorrect |
2 ms |
292 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
296 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
296 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
296 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |