제출 #491904

#제출 시각아이디문제언어결과실행 시간메모리
491904Hegdahl수열 (BOI14_sequence)C++17
25 / 100
6 ms588 KiB
#include <iostream> #include <vector> int brute(const std::vector<int> &a) { int have_digit[10][1001]; for (int d = 0; d < 10; ++d) for (int w = 1; w <= 1000; w *= 10) for (int i = d*w; i <= 1000; i += 10*w) for (int j = i; j < i+w; ++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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...