# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
200201 | wilwxk | Safety (NOI18_safety) | C++14 | 2096 ms | 504 KiB |
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>
using namespace std;
typedef long long ll;
const int MAXN = 20;
int v[MAXN], aux[MAXN], vv[MAXN];
ll ans = 1e18;
int n, x;
void brute(int id) {
if(id == n) {
for(int i = 1; i <= n; i++) {
vv[i] = v[i];
for(int j = i-1; j >= 1; j--) vv[j] = vv[j+1]+aux[j];
for(int j = i+1; j <= n; j++) vv[j] = vv[j-1]+aux[j];
ll val = 0;
for(int i = 1; i <= n; i++) val += abs(vv[i]-v[i]);
ans = min(ans, val);
}
return;
}
for(int k = -x; k <= x; k++) {
aux[id] = k;
brute(id+1);
}
}
int main() {
scanf("%d %d", &n, &x);
for(int i = 1; i <= n; i++) scanf("%d", &v[i]);
brute(1);
printf("%lld\n", ans);
}
Compilation message (stderr)
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |