Submission #4284356


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; }
//---------------------------------------------------------------------------------------------------
int gcd(int a, int b) { return a ? gcd(b%a, a) : b; }
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/






int N, M, A[11];
int need[] = { 0, 2,5,5,4,5,6,3,7,6 };
using vi = vector<int>;
#define init vi(10, 0)
//---------------------------------------------------------------------------------------------------
bool comp(vi a, vi b) {
    int sm1 = 0;
    fore(i, a) sm1 += i;

    int sm2 = 0;
    fore(i, b) sm2 += i;

    if (sm1 != sm2) return sm1 < sm2;

    rrep(i, 9, 0) if (a[i] != b[i]) return a[i] < b[i];
}
//---------------------------------------------------------------------------------------------------
string solve() {
    vector<int> ans = init;

    // 4桁ぐらいは全探索できる
    rep(a1, 0, 10) rep(a2, 0, 10) rep(a3, 0, 10) rep(a4, 0, 10) rep(r, 1, 10) {
    /*int fl = 1;
    while (fl){
        fl = 0;
        int a1 = 3;
        int a2 = 0;
        int a3 = 0;
        int a4 = 0;
        int r = 7;*/
        int cst = need[a1] + need[a2] + need[a3] + need[a4];
        int d = N - cst;

        if (d < 0) continue;

        if (A[a1] == 0) continue;
        if (A[a2] == 0) continue;
        if (A[a3] == 0) continue;
        if (A[a4] == 0) continue;
        if (A[r] == 0) continue;

        vi cand(10, 0);
        if(0 < a1) cand[a1]++;
        if (0 < a2) cand[a2]++;
        if (0 < a3) cand[a3]++;
        if (0 < a4) cand[a4]++;

        if (0 < d % need[r]) continue;
        cand[r] += d / need[r];

        if (comp(ans, cand)) {
            ans = cand;
        }
    }

    string res = "";
    rrep(i, 9, 1) {
        rep(j, 0, ans[i]) res += char('0' + i);
    }
    return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M;
    A[0] = 1;
    rep(i, 0, M) {
        int a; cin >> a;
        A[a] = 1;
    }
    cout << solve() << endl;
}

Submission Info

Submission Time
Task D - Match Matching
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 0
Code Size 3158 Byte
Status WA
Exec Time 8 ms
Memory 256 KB

Judge Result

Set Name All Sample
Score / Max Score 0 / 400 0 / 0
Status
AC × 28
WA × 1
AC × 3
Set Name Test Cases
All 0_random_1, 0_random_2, 0_random_3, 0_random_4, 0_random_5, 0_random_6, 0_random_7, 0_random_8, 1_normal_1, 1_normal_2, 1_normal_3, 1_normal_4, 1_normal_5, 1_normal_6, 2_corner_1, 2_corner_2, 2_corner_3, 2_corner_4, 2_corner_5, 2_corner_6, 3_hand_1, 3_hand_2, 3_hand_3, 3_hand_4, 3_hand_5, 3_hand_6, sample_01, sample_02, sample_03
Sample sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
0_random_1 AC 5 ms 256 KB
0_random_2 AC 2 ms 256 KB
0_random_3 AC 2 ms 256 KB
0_random_4 AC 2 ms 256 KB
0_random_5 AC 4 ms 256 KB
0_random_6 AC 2 ms 256 KB
0_random_7 AC 2 ms 256 KB
0_random_8 AC 2 ms 256 KB
1_normal_1 AC 2 ms 256 KB
1_normal_2 AC 2 ms 256 KB
1_normal_3 AC 2 ms 256 KB
1_normal_4 AC 2 ms 256 KB
1_normal_5 AC 2 ms 256 KB
1_normal_6 AC 2 ms 256 KB
2_corner_1 AC 2 ms 256 KB
2_corner_2 AC 2 ms 256 KB
2_corner_3 AC 2 ms 256 KB
2_corner_4 AC 2 ms 256 KB
2_corner_5 AC 2 ms 256 KB
2_corner_6 AC 2 ms 256 KB
3_hand_1 WA 2 ms 256 KB
3_hand_2 AC 2 ms 256 KB
3_hand_3 AC 2 ms 256 KB
3_hand_4 AC 2 ms 256 KB
3_hand_5 AC 2 ms 256 KB
3_hand_6 AC 8 ms 256 KB
sample_01 AC 2 ms 256 KB
sample_02 AC 8 ms 256 KB
sample_03 AC 2 ms 256 KB