Submission #15958

# Submission time Handle Problem Language Result Execution time Memory
15958 2015-08-02T12:19:09 Z myungwoo Sequence (BOI14_sequence) C++14
0 / 100
1000 ms 11204 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 ans = 12345678900000;

void dfs(lld n, lld v, vector<int> &arr)
{
	if (arr.empty() && ans > v){ ans = v; return; }
	if (v+n >= ans) return;
	vector <int> nxt[10];
	for (int i=0;i<10;i++){
		lld m = v + i*n;
		for (int p: arr){
			lld now = m + p;
			bool sw = 0;
			for (lld tmp=now;tmp;tmp/=10) if (tmp%10 == A[p]){ sw = 1; break; }
			if (!sw) nxt[i].pb(p);
		}
	}
	vector <int> tmp;
	for (int i=0;i<10;i++) tmp.pb(i);
	sort(all(tmp), [nxt](const int &a, const int &b){
		return sz(nxt[a]) < sz(nxt[b]);
	});
	for (int d: tmp){
		if (sz(nxt[d]) == sz(arr)) break;
		dfs(n*10, v + d*n, nxt[d]);
	}
}

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(i);
	dfs(1, 0, tmp);
	printf("%lld\n", ans);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2124 KB Output is correct
2 Correct 13 ms 2252 KB Output is correct
3 Correct 0 ms 2124 KB Output is correct
4 Correct 7 ms 2124 KB Output is correct
5 Correct 0 ms 2124 KB Output is correct
6 Correct 0 ms 2124 KB Output is correct
7 Correct 14 ms 2124 KB Output is correct
8 Incorrect 113 ms 2384 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2124 KB Output is correct
2 Correct 18 ms 2252 KB Output is correct
3 Correct 0 ms 2124 KB Output is correct
4 Correct 5 ms 2124 KB Output is correct
5 Correct 0 ms 2124 KB Output is correct
6 Correct 0 ms 2124 KB Output is correct
7 Correct 350 ms 2384 KB Output is correct
8 Correct 14 ms 2124 KB Output is correct
9 Incorrect 220 ms 2384 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2124 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2124 KB Output is correct
2 Correct 13 ms 2252 KB Output is correct
3 Correct 0 ms 2124 KB Output is correct
4 Correct 6 ms 2124 KB Output is correct
5 Execution timed out 1000 ms 11204 KB Program timed out
6 Halted 0 ms 0 KB -