Submission #15960

# Submission time Handle Problem Language Result Execution time Memory
15960 2015-08-02T13:34:55 Z myungwoo Sequence (BOI14_sequence) C++14
0 / 100
26 ms 2112 KB
#include <bits/stdc++.h>
using namespace std;

#define MAXN 100005
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
typedef long long lld;

int N;
int A[MAXN];

lld dfs(vector<int> &arr)
{
	if (sz(arr) == 1){
		lld ret = 0;
		for (int i=1;i<10;i++) if (arr[0] & (1 << i))
			ret = ret*10 + i;
		if (arr[0] & 1) ret *= 10;
		return ret;
	}
	lld ret = 12345678900000L;
	for (int i=0;i<10;i++){
		vector <int> nxt = {0};
		int k = i;
		if (sz(arr) == 2 && i == 9 && !(arr[0]&(1<<9))) continue;
		for (int t: arr){
			if (k == 10) k = 0, nxt.pb(0);
			int &b = nxt[sz(nxt)-1];
			b |= t ^ (t & (1 << k));
			k++;
		}
		ret = min(ret, dfs(nxt) * 10 + i);
	}
	return ret;
}

int main()
{
	scanf("%d", &N);
	for (int i=0;i<N;i++) scanf("%d", A+i);
	vector <int> tmp;
	for (int i=0;i<N;i++) tmp.pb(1 << A[i]);
	lld ans = dfs(tmp);
	printf("%lld\n", ans ? ans : 10);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2112 KB Output is correct
2 Correct 0 ms 2112 KB Output is correct
3 Correct 0 ms 2112 KB Output is correct
4 Incorrect 0 ms 2112 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2112 KB Output is correct
2 Correct 0 ms 2112 KB Output is correct
3 Correct 0 ms 2112 KB Output is correct
4 Incorrect 0 ms 2112 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2112 KB Output is correct
2 Correct 21 ms 2112 KB Output is correct
3 Correct 26 ms 2112 KB Output is correct
4 Incorrect 14 ms 2112 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2112 KB Output is correct
2 Correct 0 ms 2112 KB Output is correct
3 Correct 0 ms 2112 KB Output is correct
4 Incorrect 0 ms 2112 KB Output isn't correct
5 Halted 0 ms 0 KB -