답안 #921736

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
921736 2024-02-04T09:43:40 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;
    int f=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        f+=a[i];
    }
    if(h==0){
        int r=f/n-1;
        int e=0;
        int k=f/n;
        int l=f/n+1;
        int q=0,w=0;
        for(int i=1;i<=n;i++){
            q+=abs(k-a[i]);
            w+=abs(l-a[i]);
            e+=abs(r-a[i]);
            
        }
        cout<<min(q,min(w,e));
        return;
    }
    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();
	}
}


# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 344 KB Output is correct
2 Correct 44 ms 432 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Execution timed out 2085 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 11 ms 344 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 11 ms 348 KB Output is correct
5 Correct 11 ms 452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 344 KB Output is correct
2 Correct 44 ms 432 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Execution timed out 2085 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 344 KB Output is correct
2 Correct 44 ms 432 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Execution timed out 2085 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 344 KB Output is correct
2 Correct 44 ms 432 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Execution timed out 2085 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 344 KB Output is correct
2 Correct 44 ms 432 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Execution timed out 2085 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 344 KB Output is correct
2 Correct 44 ms 432 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Execution timed out 2085 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -