답안 #714428

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
714428 2023-03-24T11:16:09 Z Stickfish 수열 (BOI14_sequence) C++17
9 / 100
1000 ms 852 KB
#include <iostream>
#include <bitset>
#include <cassert>
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 = n + 1234;
    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;
        }
        if (incl0 == 0 && incl1 == 0) {
            cout << t << endl;
            return 0;
        }
    }
    assert(0);
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:66:8: warning: unused variable 'ans' [-Wunused-variable]
   66 |     ll ans = INF;
      |        ^~~
# 결과 실행 시간 메모리 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 Correct 2 ms 212 KB Output is correct
5 Correct 0 ms 312 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 6 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 8 ms 212 KB Output is correct
15 Correct 8 ms 340 KB Output is correct
# 결과 실행 시간 메모리 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 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Runtime error 12 ms 468 KB Execution killed with signal 6
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 675 ms 708 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Correct 1 ms 212 KB Output is correct
5 Execution timed out 1078 ms 852 KB Time limit exceeded
6 Halted 0 ms 0 KB -