Skip to content

Instantly share code, notes, and snippets.

@bricakeld
Last active December 8, 2017 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bricakeld/5d56ca9ffcb86544fb07fe769384b296 to your computer and use it in GitHub Desktop.
Save bricakeld/5d56ca9ffcb86544fb07fe769384b296 to your computer and use it in GitHub Desktop.
Decimal Sequences
// Asia-Tsukuba 2015 Regionals
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
int main() {
int n, temp, i, smallest, tempj;
int board[1000];
bool present[10000];
bool solved;
while (cin >> n) {
solved = false;
memset(present, false, sizeof present);
for (i = 0; i < n; i++) {
cin >> temp;
board[i] = temp;
}
// i here is num digits of the smallest integer
for (i = 0; i < n; i++) {
if (solved) break;
for (int j = 0; j < n - i; j++) {
temp = 0;
tempj = j;
for (int k = i; k >= 0; k--) {
temp += board[tempj++] * pow(10, k);
}
present[temp] = true;
}
for (int j = pow(10, i) - 1; j < pow(10, i + 1); j++) {
if (!present[j]) {
solved = true;
smallest = j;
break;
}
}
}
cout << smallest << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment