Submission #921685

# Submission time Handle Problem Language Result Execution time Memory
921685 2024-02-04T09:01:49 Z vjudge1 Safety (NOI18_safety) C++17
4 / 100
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++){
        if(z-i>=0)dfs(p+1,(z-i),an+abs(a[p]-((z-i))));
        if(z+i<=4)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 9 ms 348 KB Output is correct
2 Correct 44 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Execution timed out 2089 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 11 ms 604 KB Output is correct
3 Correct 4 ms 348 KB Output is correct
4 Correct 11 ms 456 KB Output is correct
5 Correct 11 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 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 9 ms 348 KB Output is correct
2 Correct 44 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Execution timed out 2089 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 348 KB Output is correct
2 Correct 44 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Execution timed out 2089 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 348 KB Output is correct
2 Correct 44 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Execution timed out 2089 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 348 KB Output is correct
2 Correct 44 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Execution timed out 2089 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 348 KB Output is correct
2 Correct 44 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Execution timed out 2089 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -