Submission #11111

# Submission time Handle Problem Language Result Execution time Memory
11111 2014-11-13T17:02:05 Z ainta Sequence (BOI14_sequence) C++
100 / 100
384 ms 2148 KB
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
long long Res = 99999999999999999LL;
void Do(int Num, vector<int>w, int p, int ck){
	int i, n = w.size(), j;
	if (p > 1000000)return;
	if (n == 1){
		if (ck){
			if (w[0] == 0)Res = min(Res, (long long)Num);
			return;
		}
		int tt;
		long long S = Num, P = p;
		if (w[0] & 1){
			for (i = 1; i<10; i++){
				if ((1 << i)&w[0])break;
			}
			tt = i;
			if (tt == 10){
				S += P * 10;
			}
			else{
				for (i = 9; i >= 1; i--){
					if ((1 << i)&w[0]){
						if (tt == i)P *= 10;
						S += P*i;
						P *= 10;
					}
				}
			}
		}
		else{
			for (i = 9; i >= 0; i--){
				if ((1 << i)&w[0]){
					S += P*i;
					P *= 10;
				}
			}
		}
		if (S * 10 < p) S += p;
		Res = min(Res, S);
		return;
	}
	vector<int>R((n - 1) / 10 + 1);
	if (Num * 10 >= p){
		for (j = 0; j < n; j++){
			if (j)R[j / 10] |= w[j] & ~(1 << (j % 10));
			else R[j / 10] |= w[j];
		}
		Do(Num, R, -1, 1);
	}
	if (ck)return;
	for (i = 0; i < 10; i++){
		vector<int>R((n - 1 + i) / 10 + 1);
		for (j = 0; j < n; j++){
			R[(i + j) / 10] |= w[j] & ~(1 << ((i + j) % 10));
		}
		Do(Num + i*p, R, p * 10, 0);
	}
}
int main()
{
	int i, n;
	scanf("%d", &n);
	vector<int>L(n);
	for (i = 0; i < n; i++){
		scanf("%d", &L[i]);
		L[i] = 1 << L[i];
	}
	Do(0, L, 1, 0);
	printf("%lld\n", Res);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1236 KB Output is correct
2 Correct 0 ms 1236 KB Output is correct
3 Correct 0 ms 1236 KB Output is correct
4 Correct 0 ms 1236 KB Output is correct
5 Correct 0 ms 1236 KB Output is correct
6 Correct 0 ms 1236 KB Output is correct
7 Correct 0 ms 1236 KB Output is correct
8 Correct 4 ms 1236 KB Output is correct
9 Correct 0 ms 1236 KB Output is correct
10 Correct 4 ms 1236 KB Output is correct
11 Correct 4 ms 1236 KB Output is correct
12 Correct 0 ms 1236 KB Output is correct
13 Correct 0 ms 1236 KB Output is correct
14 Correct 0 ms 1236 KB Output is correct
15 Correct 8 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1236 KB Output is correct
2 Correct 4 ms 1236 KB Output is correct
3 Correct 0 ms 1236 KB Output is correct
4 Correct 0 ms 1236 KB Output is correct
5 Correct 0 ms 1236 KB Output is correct
6 Correct 0 ms 1236 KB Output is correct
7 Correct 8 ms 1236 KB Output is correct
8 Correct 0 ms 1236 KB Output is correct
9 Correct 4 ms 1236 KB Output is correct
10 Correct 0 ms 1236 KB Output is correct
11 Correct 4 ms 1236 KB Output is correct
12 Correct 4 ms 1236 KB Output is correct
13 Correct 4 ms 1236 KB Output is correct
14 Correct 0 ms 1236 KB Output is correct
15 Correct 0 ms 1236 KB Output is correct
16 Correct 8 ms 1236 KB Output is correct
17 Correct 8 ms 1236 KB Output is correct
18 Correct 0 ms 1236 KB Output is correct
19 Correct 0 ms 1236 KB Output is correct
20 Correct 4 ms 1236 KB Output is correct
21 Correct 0 ms 1236 KB Output is correct
22 Correct 4 ms 1236 KB Output is correct
23 Correct 4 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1236 KB Output is correct
2 Correct 52 ms 1236 KB Output is correct
3 Correct 56 ms 1236 KB Output is correct
4 Correct 80 ms 1236 KB Output is correct
5 Correct 56 ms 1236 KB Output is correct
6 Correct 40 ms 1236 KB Output is correct
7 Correct 272 ms 1776 KB Output is correct
8 Correct 172 ms 1592 KB Output is correct
9 Correct 356 ms 2148 KB Output is correct
10 Correct 340 ms 2148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1236 KB Output is correct
2 Correct 0 ms 1236 KB Output is correct
3 Correct 0 ms 1236 KB Output is correct
4 Correct 0 ms 1236 KB Output is correct
5 Correct 164 ms 1576 KB Output is correct
6 Correct 0 ms 1236 KB Output is correct
7 Correct 0 ms 1236 KB Output is correct
8 Correct 4 ms 1236 KB Output is correct
9 Correct 0 ms 1236 KB Output is correct
10 Correct 0 ms 1236 KB Output is correct
11 Correct 360 ms 2148 KB Output is correct
12 Correct 376 ms 2148 KB Output is correct
13 Correct 0 ms 1236 KB Output is correct
14 Correct 4 ms 1236 KB Output is correct
15 Correct 8 ms 1236 KB Output is correct
16 Correct 8 ms 1236 KB Output is correct
17 Correct 0 ms 1236 KB Output is correct
18 Correct 0 ms 1236 KB Output is correct
19 Correct 4 ms 1236 KB Output is correct
20 Correct 8 ms 1236 KB Output is correct
21 Correct 0 ms 1236 KB Output is correct
22 Correct 0 ms 1236 KB Output is correct
23 Correct 4 ms 1236 KB Output is correct
24 Correct 0 ms 1236 KB Output is correct
25 Correct 4 ms 1236 KB Output is correct
26 Correct 4 ms 1236 KB Output is correct
27 Correct 48 ms 1236 KB Output is correct
28 Correct 56 ms 1236 KB Output is correct
29 Correct 60 ms 1236 KB Output is correct
30 Correct 48 ms 1236 KB Output is correct
31 Correct 40 ms 1236 KB Output is correct
32 Correct 252 ms 1776 KB Output is correct
33 Correct 168 ms 1592 KB Output is correct
34 Correct 364 ms 2148 KB Output is correct
35 Correct 376 ms 2148 KB Output is correct
36 Correct 260 ms 1800 KB Output is correct
37 Correct 328 ms 2000 KB Output is correct
38 Correct 228 ms 1680 KB Output is correct
39 Correct 348 ms 2148 KB Output is correct
40 Correct 384 ms 2148 KB Output is correct