Submission #4378296


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/




int N, A, B, C, L[10];
//---------------------------------------------------------------------------------------------------
int ans = inf;
int flag[8];
void dfs(int cu) {
    if (cu == N) {
        int a = 0, b = 0, c = 0;
        int ca = 0, cb = 0, cc = 0;
        rep(i, 0, N) {
            if (flag[i] == 0) a += L[i], ca++;
            else if (flag[i] == 1) b += L[i], cb++;
            else if (flag[i] == 2) c += L[i], cc++;
        }
        if (0 == ca or 0 == cb or 0 == cc) return;
        int cand = (ca-1) * 10 + (cb-1) * 10 + (cc-1) * 10;
        cand += abs(A - a) + abs(B - b) + abs(C - c);
        chmin(ans, cand);
        return;
    }

    rep(i, 0, 4) {
        flag[cu] = i;
        dfs(cu + 1);
    }
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> A >> B >> C;
    rep(i, 0, N) cin >> L[i];

    dfs(0);
    cout << ans << endl;
}

Submission Info

Submission Time
Task C - Synthetic Kadomatsu
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 300
Code Size 2227 Byte
Status AC
Exec Time 4 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 20
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20
Case Name Status Exec Time Memory
a01 AC 1 ms 256 KB
a02 AC 4 ms 256 KB
a03 AC 4 ms 256 KB
b04 AC 1 ms 256 KB
b05 AC 4 ms 256 KB
b06 AC 1 ms 256 KB
b07 AC 1 ms 256 KB
b08 AC 2 ms 256 KB
b09 AC 2 ms 256 KB
b10 AC 4 ms 256 KB
b11 AC 4 ms 256 KB
b12 AC 4 ms 256 KB
b13 AC 4 ms 256 KB
b14 AC 4 ms 256 KB
b15 AC 4 ms 256 KB
b16 AC 4 ms 256 KB
b17 AC 4 ms 256 KB
b18 AC 4 ms 256 KB
b19 AC 4 ms 256 KB
b20 AC 4 ms 256 KB