답안 #714427

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
714427 2023-03-24T11:13:17 Z Stickfish 수열 (BOI14_sequence) C++17
0 / 100
4 ms 320 KB
#include <iostream>
#include <bitset>
using namespace std;
using ll = long long;

const int MAXN = 1e5 + 123;
const ll INF = 1e18 + 177013;
int dgseq[MAXN];
bitset<10> dgs[MAXN];

bool in(int x, int n) {
    while (n > 0) {
        if (n % 10 == x)
            return true;
        n /= 10;
    }
    return false;
}

ll get_best(bitset<10> incl) {
    ll ans = 0;
    for (int t = 1; t < 10; ++t) {
        if (!incl[t])
            continue;
        ans += t;
        ans *= 10;
        if (incl[0]) {
            ans *= 10;
            incl[0] = 0;
        }
    }
    return ans;
}

ll get_best_conseq(bitset<10> incl0, bitset<10> incl1) {
    if (incl0 == 0 && incl1 == 0)
        return 0;
    ll ans = INF;
    for (int d = 0; d < 9; ++d) {
        bitset<10> nincl0 = incl0;
        bitset<10> nincl1 = incl1;
        nincl0[d] = nincl1[d + 1] = 0;
        ans = min(get_best(nincl0 | nincl1) * 10 + d, ans);
    }
    if (incl0[9] || incl1[0]) {
        incl0[9] = incl1[0] = 0;
        ans = min(ans, get_best_conseq(incl0, incl1) * 10 + 9);
    }
    return ans;
}

signed main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> dgseq[i];
    int m = 1;
    while (m < n)
        m *= 10;
    for (int t = 0; t < m; ++t) { 
        int x = t;
        while (x > 0) {
            dgs[t][x % 10] = 1;
            x /= 10;
        }
    }
    ll ans = INF;
    for (int t = 0; t < m; ++t) {
        bitset<10> incl0;
        bitset<10> incl1;
        for (int k = 0; k < n; ++k) {
            if (dgs[(t + k) % m][dgseq[k]])
                continue;
            if (t + k < m)
                incl0[dgseq[k]] = 1;
            else
                incl1[dgseq[k]] = 1;
        }
        ans = min(ans, get_best_conseq(incl0, incl1) * m + t);
    }
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 320 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 4 ms 312 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Incorrect 1 ms 316 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 4 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -