Submission #1055045

# Submission time Handle Problem Language Result Execution time Memory
1055045 2024-08-12T14:12:28 Z FaustasK Safety (NOI18_safety) C++14
8 / 100
136 ms 3808 KB
#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
1 Correct 28 ms 344 KB Output is correct
2 Correct 134 ms 404 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 131 ms 348 KB Output is correct
5 Correct 136 ms 344 KB Output is correct
6 Correct 8 ms 348 KB Output is correct
7 Correct 39 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 9 ms 432 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 3280 KB Output is correct
2 Correct 47 ms 3788 KB Output is correct
3 Correct 49 ms 3808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 344 KB Output is correct
2 Correct 134 ms 404 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 131 ms 348 KB Output is correct
5 Correct 136 ms 344 KB Output is correct
6 Correct 8 ms 348 KB Output is correct
7 Correct 39 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 9 ms 432 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 344 KB Output is correct
2 Correct 134 ms 404 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 131 ms 348 KB Output is correct
5 Correct 136 ms 344 KB Output is correct
6 Correct 8 ms 348 KB Output is correct
7 Correct 39 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 9 ms 432 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 344 KB Output is correct
2 Correct 134 ms 404 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 131 ms 348 KB Output is correct
5 Correct 136 ms 344 KB Output is correct
6 Correct 8 ms 348 KB Output is correct
7 Correct 39 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 9 ms 432 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 344 KB Output is correct
2 Correct 134 ms 404 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 131 ms 348 KB Output is correct
5 Correct 136 ms 344 KB Output is correct
6 Correct 8 ms 348 KB Output is correct
7 Correct 39 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 9 ms 432 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 344 KB Output is correct
2 Correct 134 ms 404 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 131 ms 348 KB Output is correct
5 Correct 136 ms 344 KB Output is correct
6 Correct 8 ms 348 KB Output is correct
7 Correct 39 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 9 ms 432 KB Output isn't correct
10 Halted 0 ms 0 KB -