This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <algorithm>
#include <iostream>
#include <vector>
int brute(const std::vector<int> &a) {
int have_digit[10][2001];
for (int d = 0; d < 10; ++d)
for (int w = 1; w <= 2000; w *= 10)
for (int i = d*w; i <= 2000; i += 10*w)
for (int j = i; j < std::min(i+w, 2000); ++j)
have_digit[d][j] = 1;
int n = 0;
bool ok;
do {
++n;
ok = true;
for (int i = 0; i < (int)a.size(); ++i)
ok &= have_digit[a[i]][n+i];
} while (!ok);
return n;
}
int main() {
std::cin.tie(0)->sync_with_stdio(0);
int k;
std::cin >> k;
std::vector<int> a(k);
for (int &x : a)
std::cin >> x;
int x = a[0];
bool all_same = true;
for (int i = 1; i < k; ++i)
all_same &= a[i] == x;
if (!all_same) {
std::cout << brute(a) << '\n';
return 0;
}
int v;
if (x == 0) {
v = 10;
int cnt = 1;
while (cnt < k) {
v = 10*v;
cnt = 10*cnt + 1;
}
} else if (x == 9) {
v = 9;
int cnt = 1;
while (cnt < k) {
v = 10*v - 1;
cnt = 10*cnt + 1;
}
} else {
v = x;
int cnt = 1;
while (cnt < k) {
v = 10*v;
cnt = 10*cnt;
}
}
std::cout << v << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |