답안 #418002

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
418002 2021-06-04T20:27:35 Z KULIKOLD 수열 (BOI14_sequence) C++17
100 / 100
331 ms 182208 KB
//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define endl '\n'
const ll DIM = 1E5+7;
const ll DIV = 7;
const ll MAXN = 11;
const ll SZ = 1<<10;
const ll INF = 1E18;
ll A[DIM],dp[DIM][DIV][MAXN],dp1[DIM][DIV][MAXN],suf[DIM][DIV][MAXN],po[DIV];
ll F(ll num,ll digit){
    while(num){
        if (num%10==digit)
            return 0;
        num/=10;
    }
    return 1<<digit;
}
void anchor(){
    ll h;
    ++h;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    po[0] = 1;
    for(ll i = 1;i<DIV;++i)
        po[i] = po[i-1]*10;
    ll n;
    cin>>n;
    for(ll i = 1;i<=n;++i){
        cin>>A[i];
    }
    for(ll i = 1;i<=n;++i){
        ll cur = 1<<A[i];
        for(ll div = 0;div<DIV;++div){
            for(ll num = 1;num<=10;++num){
                ll mask = 0;
                ll mask1 = 0;
                if (num>1 && i-po[div]>=1){
                    mask|=dp[i-po[div]][div][num-1]|F(po[div]*(num-1),A[i-po[div]]);
                    mask1|=dp1[i-po[div]][div][num-1]|F(po[div]*(num-1),A[i-po[div]]);
                }
                ll tmp = (SZ-1)^(1<<(num-1));
                ll tmp1 = tmp;
                if (num==1)
                    tmp = SZ-1;

                if (div>0){
                    if (num>1)
                        mask|=dp1[i][div-1][10]&tmp;
                    else mask|=dp[i][div-1][10]&tmp;
                    mask1|=dp1[i][div-1][10]&tmp1;
                }
                dp[i][div][num] = mask;
                dp1[i][div][num] = mask1;
            }

        }
    }
    for(ll i = n;i>=1;--i){
        ll cur = 1<<A[i];
        for(ll div = 0;div<DIV;++div){
            for(ll num = 0;num<=9;++num){
                ll mask = 0;
                if (num<9 && i+po[div]<=n){
                    mask|=suf[i+po[div]][div][num+1]|F(po[div]*(num+1),A[i+po[div]]);
                }
                ll tmp = (SZ-1)^(1<<num);
                if (div>0){
                    mask|=suf[i][div-1][0]&tmp;
                }
                suf[i][div][num] = mask;
            }
        }
    }
    ll ans = 0;
    for(ll r = 1;r<=1000;++r) {
        ll flag = 0;
        for (ll i = 1; i <= n; ++i) {
            if (F(r + i - 1, A[i]))
                flag = 1;
        }
        if (!flag){
            ans = r;
            break;
        }
    }
    ll res = INF;
    for(ll i = 1;i<=n;++i){
        for(ll div = 0;div<DIV;++div) {
            for (ll num = 1; num <= 9; ++num) {
                if (num * po[div] < i || po[div]*(10-num)-1+i<n)
                    continue;
                ll mask = F(po[div] * num, A[i]) | suf[i][div][num];
                if (num==1) {
                    mask |= dp1[i][div][num];
                    if(dp[i][div][num]!=dp1[i][div][num] && mask==0)
                        mask = 2;

                } else {
                    mask |= dp[i][div][num];
                }
                ll r = 0;
                if (mask == 1) {
                    r = 10;
                } else {
                    for (ll bit = 1; bit <= 9; ++bit) {
                        if (mask & (1 << bit)) {
                            r = r * 10 + bit;
                            if (mask & 1) {
                                r = r * 10;
                                mask ^= 1;
                            }
                        }
                    }
                }
                r = r * 10 + num;
                r*=po[div];
                r-=i-1;

                res = min(res,r);

            }
        }
    }

    cout<<res<<endl;
    return 0;
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:38:12: warning: unused variable 'cur' [-Wunused-variable]
   38 |         ll cur = 1<<A[i];
      |            ^~~
sequence.cpp:65:12: warning: unused variable 'cur' [-Wunused-variable]
   65 |         ll cur = 1<<A[i];
      |            ^~~
sequence.cpp:80:8: warning: variable 'ans' set but not used [-Wunused-but-set-variable]
   80 |     ll ans = 0;
      |        ^~~
sequence.cpp: In function 'void anchor()':
sequence.cpp:23:5: warning: 'h' is used uninitialized in this function [-Wuninitialized]
   23 |     ++h;
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 972 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 448 KB Output is correct
8 Correct 3 ms 2124 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 3 ms 1740 KB Output is correct
11 Correct 3 ms 1740 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 3 ms 2124 KB Output is correct
15 Correct 3 ms 2120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 972 KB Output is correct
3 Correct 1 ms 448 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 3 ms 2124 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 3 ms 2124 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 3 ms 2112 KB Output is correct
12 Correct 3 ms 1728 KB Output is correct
13 Correct 3 ms 1728 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 3 ms 2124 KB Output is correct
17 Correct 3 ms 2124 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 844 KB Output is correct
20 Correct 3 ms 1984 KB Output is correct
21 Correct 1 ms 700 KB Output is correct
22 Correct 3 ms 2124 KB Output is correct
23 Correct 3 ms 2124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 32 ms 20428 KB Output is correct
3 Correct 33 ms 20536 KB Output is correct
4 Correct 19 ms 20468 KB Output is correct
5 Correct 21 ms 20492 KB Output is correct
6 Correct 24 ms 14888 KB Output is correct
7 Correct 227 ms 126424 KB Output is correct
8 Correct 150 ms 82500 KB Output is correct
9 Correct 317 ms 182108 KB Output is correct
10 Correct 322 ms 182208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 972 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 444 KB Output is correct
5 Correct 143 ms 79044 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 3 ms 2124 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 3 ms 2124 KB Output is correct
11 Correct 331 ms 182188 KB Output is correct
12 Correct 323 ms 181988 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 3 ms 2124 KB Output is correct
15 Correct 3 ms 1740 KB Output is correct
16 Correct 3 ms 1740 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 3 ms 2124 KB Output is correct
20 Correct 3 ms 2252 KB Output is correct
21 Correct 1 ms 588 KB Output is correct
22 Correct 1 ms 844 KB Output is correct
23 Correct 4 ms 1996 KB Output is correct
24 Correct 1 ms 704 KB Output is correct
25 Correct 3 ms 2124 KB Output is correct
26 Correct 3 ms 2124 KB Output is correct
27 Correct 32 ms 20428 KB Output is correct
28 Correct 32 ms 20428 KB Output is correct
29 Correct 19 ms 20428 KB Output is correct
30 Correct 20 ms 20464 KB Output is correct
31 Correct 24 ms 14828 KB Output is correct
32 Correct 229 ms 126500 KB Output is correct
33 Correct 151 ms 82368 KB Output is correct
34 Correct 318 ms 182068 KB Output is correct
35 Correct 327 ms 182132 KB Output is correct
36 Correct 245 ms 130976 KB Output is correct
37 Correct 320 ms 177092 KB Output is correct
38 Correct 195 ms 103488 KB Output is correct
39 Correct 323 ms 182084 KB Output is correct
40 Correct 331 ms 182164 KB Output is correct