# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1055045 | FaustasK | Safety (NOI18_safety) | C++14 | 136 ms | 3808 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;
const long long daug = 1000000000000000;
int n, h;
int I[10];
vector <int> V;
int c = 0;
long long kiek()
{
c++;
for(int i = 1; i<n; i++)
{
if(abs(I[i] - I[i-1]) > h) return daug;
}
long long ats = 0;
for(int i = 0; i<n; i++)
{
ats += abs(V[i] - I[i]);
}
return ats;
}
int main()
{
cin >> n >> h;
int M[n];
for(int i = 0; i<n; i++)
{
int x;
cin >> x;
V.push_back(x);
M[i] = x;
}
long long ats = 0;
if(h == 0)
{
sort(M, M+n);
int vidurkis = M[n/2];
for(int i = 0; i<n; i++)
{
ats += abs(M[i] - vidurkis);
}
cout << ats;
return 0;
}
long long atsakymas = daug;
if(n >= 1)
{
for(I[0] = 0; I[0] <=4; I[0]++)
{
if(n == 1) atsakymas = min(atsakymas, kiek());
if(n >= 2)
{
for(I[1] = 0; I[1] <=4; I[1]++)
{
if(n == 2) atsakymas = min(atsakymas, kiek());
if(n >= 3)
{
for(I[2] = 0; I[2] <=4; I[2]++)
{
if(n == 3) atsakymas = min(atsakymas, kiek());
if(n >= 4)
{
for(I[3] = 0; I[3] <=4; I[3]++)
{
if(n == 4) atsakymas = min(atsakymas, kiek());
if(n >= 5)
{
for(I[4] = 0; I[4] <=4; I[4]++)
{
if(n == 5) atsakymas = min(atsakymas, kiek());
if(n >= 6)
{
for(I[5] = 0; I[5] <=4; I[5]++)
{
if(n == 6) atsakymas = min(atsakymas, kiek());
if(n >= 7)
{
for(I[6] = 0; I[6] <=4; I[6]++)
{
if(n == 7) atsakymas = min(atsakymas, kiek());
if(n >= 8)
{
for(I[7] = 0; I[7] <=4; I[7]++)
{
if(n == 8) atsakymas = min(atsakymas, kiek());
if(n >= 9)
{
for(I[8] = 0; I[8] <=4; I[8]++)
{
if(n == 9) atsakymas = min(atsakymas, kiek());
if(n >= 10)
{
for(I[9] = 0; I[9] <=4; I[9]++)
{
if(n == 10) atsakymas = min(atsakymas, kiek());
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
cout << atsakymas;
return 0;
}
# | 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... |