Submission #1055045

#TimeUsernameProblemLanguageResultExecution timeMemory
1055045FaustasKSafety (NOI18_safety)C++14
8 / 100
136 ms3808 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...