답안 #400029

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
400029 2021-05-07T07:54:52 Z lyc 수열 (BOI14_sequence) C++14
100 / 100
130 ms 1108 KB
#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
typedef long long ll;

const int mxK = 1e5+5;

int K;

ll solve(vector<int>& req, bool pad) {
    ll ret = 0;
    if (SZ(req) == 1) {
        bool zero = 0;
        FOR(i,1,9) if (req[0] & (1<<i)) {
            ret = ret*10 + i;
            if ((req[0]&1) && !zero) {
                ret = ret*10;
                zero = 1;
            }
        }
        if ((req[0]&1) && !zero && pad) {
            ret = 10;
        }
    } else {
        ret = 1e18;
        FOR(d,0,9){
            vector<int> req2;
            FOR(i,0,SZ(req)-1){
                int cur = req[i] & (~(1<<((i+d)%10)));
                if (i == 0 || (i+d)/10 != (i-1+d)/10) {
                    req2.push_back(cur);
                } else {
                    req2.back() |= cur;
                }
            }

            if (req == req2) continue; // corner case
            ll a = solve(req2,1);
            ll cur = a*10 + d;
            if (cur == 0 && (req[0]&1) && pad) cur = 10;
            ret = min(ret,cur);
        }
    }
    return ret;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    cin >> K;

    vector<int> req;
    FOR(i,1,K){
        int A; cin >> A;
        req.push_back(1<<A);
    }

    cout << solve(req,1) << '\n';
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 2 ms 320 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 2 ms 204 KB Output is correct
11 Correct 2 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 2 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 2 ms 316 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 2 ms 312 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 412 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 312 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 2 ms 208 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 2 ms 204 KB Output is correct
23 Correct 2 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 14 ms 448 KB Output is correct
3 Correct 13 ms 332 KB Output is correct
4 Correct 13 ms 456 KB Output is correct
5 Correct 14 ms 332 KB Output is correct
6 Correct 7 ms 332 KB Output is correct
7 Correct 54 ms 1104 KB Output is correct
8 Correct 52 ms 720 KB Output is correct
9 Correct 72 ms 1104 KB Output is correct
10 Correct 72 ms 1088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 63 ms 592 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 2 ms 204 KB Output is correct
11 Correct 73 ms 1108 KB Output is correct
12 Correct 115 ms 1104 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 2 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 2 ms 204 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 2 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 2 ms 204 KB Output is correct
26 Correct 2 ms 204 KB Output is correct
27 Correct 13 ms 332 KB Output is correct
28 Correct 13 ms 448 KB Output is correct
29 Correct 13 ms 448 KB Output is correct
30 Correct 13 ms 448 KB Output is correct
31 Correct 7 ms 332 KB Output is correct
32 Correct 52 ms 1104 KB Output is correct
33 Correct 52 ms 720 KB Output is correct
34 Correct 73 ms 1104 KB Output is correct
35 Correct 71 ms 1104 KB Output is correct
36 Correct 94 ms 1104 KB Output is correct
37 Correct 130 ms 1104 KB Output is correct
38 Correct 76 ms 720 KB Output is correct
39 Correct 128 ms 1104 KB Output is correct
40 Correct 128 ms 1104 KB Output is correct