답안 #338740

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
338740 2020-12-23T19:23:24 Z limabeans 수열 (BOI14_sequence) C++17
100 / 100
163 ms 1516 KB
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;
const ll inf = 8e18;




ll solve(vector<int> a, bool flag9=true) {
    int n = a.size();
    if (n==1) {
	ll res = 0;
	for (int x=1; x<=9; x++) {
	    if (a[0]>>x&1) {
		res=res*10 + x;
		if (res==x && (a[0]&1)) {
		    // x is first digit, and we need 0
		    res=res*10;
		}
	    }
	}
	if (res==0 && (a[0]&1)) {
	    res = 10; //only 0
	}
	return res;
    } else {

	ll lo = inf;
	// iterate over last digit
	for (int x=0; x<9+flag9; x++) {
	    int d = x;
	    int mask = 0;
	    vector<int> na;
	    bool zero = false;
	    for (int i=0; i<n; i++) {
		mask |= (a[i] & (1023 ^ (1<<d)));
		if (d==0 && (a[i]&1)) {
		    zero = true;
		}
		d = (d+1) % 10;
		if (d==0 || i==n-1) {
		    na.push_back(mask);
		    mask = 0;
		}
	    }

	    ll cur = solve(na, !(n==2 && x==9))*10 + x;
	    if (cur==0 && zero) cur = 10;
	    lo = min(lo, cur);
	}

	return lo;
    }
}


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

    int n;
    cin>>n;
    vector<int> a(n);
    for (int i=0; i<n; i++) {
	int d;
	cin>>d;
	a[i] = (1<<d);
	
    }
    cout<<solve(a)<<endl;    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 3 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 3 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 392 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 17 ms 492 KB Output is correct
3 Correct 20 ms 492 KB Output is correct
4 Correct 17 ms 492 KB Output is correct
5 Correct 22 ms 528 KB Output is correct
6 Correct 12 ms 364 KB Output is correct
7 Correct 106 ms 1132 KB Output is correct
8 Correct 74 ms 876 KB Output is correct
9 Correct 146 ms 1388 KB Output is correct
10 Correct 146 ms 1388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 93 ms 876 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 153 ms 1388 KB Output is correct
12 Correct 149 ms 1388 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 2 ms 364 KB Output is correct
27 Correct 17 ms 492 KB Output is correct
28 Correct 17 ms 492 KB Output is correct
29 Correct 18 ms 492 KB Output is correct
30 Correct 17 ms 492 KB Output is correct
31 Correct 13 ms 364 KB Output is correct
32 Correct 107 ms 1176 KB Output is correct
33 Correct 71 ms 876 KB Output is correct
34 Correct 147 ms 1388 KB Output is correct
35 Correct 146 ms 1388 KB Output is correct
36 Correct 117 ms 1132 KB Output is correct
37 Correct 156 ms 1516 KB Output is correct
38 Correct 97 ms 1004 KB Output is correct
39 Correct 156 ms 1388 KB Output is correct
40 Correct 163 ms 1388 KB Output is correct