답안 #491905

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
491905 2021-12-04T23:54:55 Z Hegdahl 수열 (BOI14_sequence) C++17
25 / 100
6 ms 588 KB
#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';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Incorrect 1 ms 304 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 6 ms 588 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 5 ms 588 KB Output is correct
10 Correct 5 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Incorrect 0 ms 332 KB Output isn't correct
5 Halted 0 ms 0 KB -