Submission #105984

#TimeUsernameProblemLanguageResultExecution timeMemory
105984xiaowuc1Sequence (BOI14_sequence)C++14
34 / 100
908 ms40076 KiB
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef vector<vector<ll>> matrix;

const int MAX_N = 10000000;
short valid[MAX_N];

void gen(int x) {
	int y = x;
	while(y) {
		valid[x] |= 1 << (y%10);
		y /= 10;
	}
}

int l[100000];
int n;
void solve() {
	for(int i = 0; i < MAX_N; i++) gen(i);
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> l[i];
	}
	int ret = 1;
	while(true) {
		bool good = true;
		for(int i = 0; good && i < n; i++) {
			good = (valid[ret+i] & (1 << l[i]));
		}
		if(good) {
			cout << ret << endl;
			break;
		}
		ret++;
	}
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
	/*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
	*/
	solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...