# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
921670 |
2024-02-04T08:56:14 Z |
vjudge1 |
Safety (NOI18_safety) |
C++17 |
|
2000 ms |
604 KB |
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
//#define int long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define str string
#define pii pair<int,int>
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define mii map<int,int>
#define mll map<ll,ll>
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yess cout<<"Yes\n";
#define noo cout<<"No\n";
using namespace std;
#define maxn 1111111
#define mod 1000000007
int ans=100000000;
int n,h;
int a[101];
int j=0;
void dfs(int p,int z,int an){
if(p>n){
ans=min(ans,an);
return;
}
dfs(p+1,z,an+abs(a[p]-z));
for(int i=1;i<=h;i++){
dfs(p+1,abs(z-i),an+abs(a[p]-(abs(z-i))));
dfs(p+1,abs(z+i),an+abs(a[p]-(abs(z+i))));
}
}
void solve(){
cin>>n>>h;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=0;i<=4;i++){
dfs(2,i,abs(a[1]-i));
}
cout<<ans;
}
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
//srand( time(0));
//freopen("sum.in", "r", stdin);
//freopen("sum.out", "w", stdout);
int tests=1;
//cin>>tests;
for(int i=1;i<=tests;i++){
//cout<<"Case "<<i<<": \n";
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
797 ms |
432 KB |
Output is correct |
2 |
Execution timed out |
2033 ms |
344 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
37 ms |
452 KB |
Output is correct |
3 |
Correct |
12 ms |
348 KB |
Output is correct |
4 |
Correct |
36 ms |
348 KB |
Output is correct |
5 |
Correct |
39 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
797 ms |
432 KB |
Output is correct |
2 |
Execution timed out |
2033 ms |
344 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
797 ms |
432 KB |
Output is correct |
2 |
Execution timed out |
2033 ms |
344 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
797 ms |
432 KB |
Output is correct |
2 |
Execution timed out |
2033 ms |
344 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
797 ms |
432 KB |
Output is correct |
2 |
Execution timed out |
2033 ms |
344 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
797 ms |
432 KB |
Output is correct |
2 |
Execution timed out |
2033 ms |
344 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |