Submission #230084

# Submission time Handle Problem Language Result Execution time Memory
230084 2020-05-08T06:49:22 Z dolphingarlic Sequence (BOI14_sequence) C++14
100 / 100
215 ms 1528 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;
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:66:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
sequence.cpp:69:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &L[i]);
   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 6 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 8 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 8 ms 256 KB Output is correct
11 Correct 7 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 8 ms 256 KB Output is correct
15 Correct 8 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 8 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 8 ms 256 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 8 ms 256 KB Output is correct
12 Correct 7 ms 384 KB Output is correct
13 Correct 7 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 8 ms 384 KB Output is correct
17 Correct 8 ms 256 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
19 Correct 5 ms 256 KB Output is correct
20 Correct 8 ms 256 KB Output is correct
21 Correct 5 ms 256 KB Output is correct
22 Correct 8 ms 384 KB Output is correct
23 Correct 8 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 34 ms 384 KB Output is correct
3 Correct 34 ms 384 KB Output is correct
4 Correct 33 ms 384 KB Output is correct
5 Correct 34 ms 384 KB Output is correct
6 Correct 31 ms 384 KB Output is correct
7 Correct 143 ms 1144 KB Output is correct
8 Correct 98 ms 768 KB Output is correct
9 Correct 197 ms 1280 KB Output is correct
10 Correct 201 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 6 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 93 ms 640 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 8 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 8 ms 256 KB Output is correct
11 Correct 201 ms 1152 KB Output is correct
12 Correct 195 ms 1400 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Correct 8 ms 256 KB Output is correct
15 Correct 8 ms 256 KB Output is correct
16 Correct 7 ms 256 KB Output is correct
17 Correct 5 ms 256 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 8 ms 256 KB Output is correct
20 Correct 8 ms 256 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 6 ms 384 KB Output is correct
23 Correct 8 ms 256 KB Output is correct
24 Correct 5 ms 256 KB Output is correct
25 Correct 8 ms 384 KB Output is correct
26 Correct 8 ms 256 KB Output is correct
27 Correct 35 ms 504 KB Output is correct
28 Correct 37 ms 384 KB Output is correct
29 Correct 33 ms 384 KB Output is correct
30 Correct 33 ms 384 KB Output is correct
31 Correct 26 ms 384 KB Output is correct
32 Correct 139 ms 896 KB Output is correct
33 Correct 101 ms 768 KB Output is correct
34 Correct 201 ms 1280 KB Output is correct
35 Correct 196 ms 1280 KB Output is correct
36 Correct 149 ms 1032 KB Output is correct
37 Correct 202 ms 1272 KB Output is correct
38 Correct 131 ms 768 KB Output is correct
39 Correct 207 ms 1272 KB Output is correct
40 Correct 215 ms 1528 KB Output is correct