답안 #584698

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
584698 2022-06-27T20:36:58 Z MohammadAghil 수열 (BOI14_sequence) C++17
100 / 100
175 ms 1420 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast,unroll-loops")

using namespace std;

typedef long long ll;
typedef pair<int, int> pp;

#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define sz(x) (int)x.size()
#define ff first
#define ss secounf 
#define all(x) begin(x), end(x)
#define pb push_back

const ll mod = 1e9+7, maxn = 5e2+1, inf = ll(1e9)+5;

ll slv(vector<int> a, bool can = true){
     bool ok = false;
     for(int c: a) ok |= c > 0;
     if(!ok) return 0;
     if(sz(a) == 1){
          int x = a[0], res = 0, mn = 0;
          if(x&1){
               mn = 1;
               per(i,10,1) if(x>>i&1) mn = i;
               res = mn*10;
          }
          rep(i,mn+1,10) if(x>>i&1) res = res*10 + i;
          return res;
     }
     // cout << sz(a) << endl;
     ll ans = 10987654321000000ll;
     rep(d,0,10){
          if(d == 9 && !can) break;
          vector<int> b{0};
          bool has_zero = false;
          int cr = d;
          rep(i,0,sz(a)){
               if(a[i]>>cr&1) b.back() |= a[i]^(1<<cr);
               else b.back() |= a[i];
               if(!cr && (a[i]&1)) has_zero = true; 
               cr++;
               if(cr == 10) {
                    cr = 0;
                    if(i - sz(a) + 1) b.pb(0);
               }
          }
          // cout << sz(b) << '\n';
          ll res = slv(b, d != 9 || sz(a) > 2)*10 + d;
          if(!res && has_zero) res = 10;
          ans = min(ans, res);
     }
     return ans;
}

int main(){
     cin.tie(0) -> sync_with_stdio(0);
     int n; cin >> n;
     vector<int> a(n);
     rep(i,0,n){
          cin >> a[i], a[i] = 1<<a[i]; 
     }
     cout << slv(a) << '\n';
     return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 0 ms 324 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 2 ms 324 KB Output is correct
15 Correct 2 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 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 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 2 ms 324 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 2 ms 320 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 2 ms 320 KB Output is correct
23 Correct 2 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 15 ms 448 KB Output is correct
3 Correct 15 ms 340 KB Output is correct
4 Correct 16 ms 448 KB Output is correct
5 Correct 16 ms 468 KB Output is correct
6 Correct 11 ms 340 KB Output is correct
7 Correct 104 ms 1088 KB Output is correct
8 Correct 77 ms 724 KB Output is correct
9 Correct 175 ms 1416 KB Output is correct
10 Correct 131 ms 1420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 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 65 ms 724 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 320 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 320 KB Output is correct
11 Correct 132 ms 1308 KB Output is correct
12 Correct 127 ms 1420 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 2 ms 212 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 3 ms 212 KB Output is correct
20 Correct 2 ms 212 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 212 KB Output is correct
26 Correct 2 ms 212 KB Output is correct
27 Correct 15 ms 340 KB Output is correct
28 Correct 16 ms 332 KB Output is correct
29 Correct 16 ms 448 KB Output is correct
30 Correct 16 ms 340 KB Output is correct
31 Correct 11 ms 332 KB Output is correct
32 Correct 95 ms 1084 KB Output is correct
33 Correct 63 ms 724 KB Output is correct
34 Correct 128 ms 1420 KB Output is correct
35 Correct 129 ms 1364 KB Output is correct
36 Correct 100 ms 1120 KB Output is correct
37 Correct 131 ms 1360 KB Output is correct
38 Correct 92 ms 960 KB Output is correct
39 Correct 157 ms 1412 KB Output is correct
40 Correct 136 ms 1420 KB Output is correct