답안 #377821

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
377821 2021-03-15T08:04:50 Z thecodingwizard 수열 (BOI14_sequence) C++11
100 / 100
551 ms 1516 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
#define ii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define F0R(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define inf 1000000010

ll solve(vector<int> need, int depth) {
    if (depth > 12) return -1;

    if (need.size() == 1) {
        ll ans = 0;
        bool needzero = false;
        F0R(i, 10) {
            int j = i;
            if (need[0] & (1 << j)) {
                if (j == 0) {
                    needzero = 1;
                } else {
                    ans = ans*10+j;
                    if (needzero) {
                        ans = ans*10;
                        needzero = 0;
                    }
                }
            }
        }
        if (ans == 0 && needzero) return 10;
        return ans;
    }

    ll ans = -1;
    F0R(lastDigit, 10) {
        vector<int> next;
        int curDigit = lastDigit;
        int curMask = 0;

        for (auto x : need) {
            curMask |= x & ~(1 << curDigit);

            curDigit++;
            if (curDigit == 10) {
                next.pb(curMask);
                curDigit = 0;
                curMask = 0;
            }
        }
        if (curDigit != 0) next.pb(curMask);

        ll ans2 = solve(next, depth + 1);
        if (ans2 == -1) continue;
        ll nxt = ans2*10+lastDigit;
        if (lastDigit == 0 && ans2 == 0 && need[0] != 0) nxt = 10;
        if (ans == -1 || nxt < ans) {
            ans = nxt;
        }
    }
    return ans;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);

    int k; cin >> k;
    vector<int> A;
    F0R(i, k) {
        int x; cin >> x;
        A.pb(1 << x);
    }

    cout << solve(A, 1) << endl;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 5 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 7 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 6 ms 364 KB Output is correct
11 Correct 6 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 8 ms 364 KB Output is correct
15 Correct 7 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 4 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 7 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 7 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 8 ms 364 KB Output is correct
12 Correct 6 ms 364 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 8 ms 364 KB Output is correct
17 Correct 8 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 3 ms 492 KB Output is correct
20 Correct 7 ms 364 KB Output is correct
21 Correct 4 ms 364 KB Output is correct
22 Correct 9 ms 492 KB Output is correct
23 Correct 7 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 63 ms 492 KB Output is correct
3 Correct 62 ms 492 KB Output is correct
4 Correct 62 ms 492 KB Output is correct
5 Correct 60 ms 492 KB Output is correct
6 Correct 62 ms 492 KB Output is correct
7 Correct 347 ms 1132 KB Output is correct
8 Correct 231 ms 880 KB Output is correct
9 Correct 502 ms 1316 KB Output is correct
10 Correct 500 ms 1388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 3 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 242 ms 996 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 9 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 8 ms 364 KB Output is correct
11 Correct 511 ms 1388 KB Output is correct
12 Correct 505 ms 1516 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 7 ms 364 KB Output is correct
15 Correct 7 ms 492 KB Output is correct
16 Correct 6 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 8 ms 364 KB Output is correct
20 Correct 7 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 3 ms 364 KB Output is correct
23 Correct 7 ms 364 KB Output is correct
24 Correct 3 ms 364 KB Output is correct
25 Correct 8 ms 364 KB Output is correct
26 Correct 8 ms 364 KB Output is correct
27 Correct 62 ms 532 KB Output is correct
28 Correct 62 ms 492 KB Output is correct
29 Correct 61 ms 492 KB Output is correct
30 Correct 61 ms 620 KB Output is correct
31 Correct 57 ms 492 KB Output is correct
32 Correct 346 ms 1260 KB Output is correct
33 Correct 227 ms 880 KB Output is correct
34 Correct 500 ms 1408 KB Output is correct
35 Correct 497 ms 1516 KB Output is correct
36 Correct 393 ms 1260 KB Output is correct
37 Correct 513 ms 1516 KB Output is correct
38 Correct 313 ms 1008 KB Output is correct
39 Correct 544 ms 1516 KB Output is correct
40 Correct 551 ms 1388 KB Output is correct