Logo
(追記) (追記ここまで)

21352번 - Fibonacci Strings 다국어언어 제한함수 구현

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB2310952.941%

문제

Aron likes Fibonacci numbers. He likes them so much he actually got bored of the numbers themselves and decided to invent other combinatorial objects based on them instead.

His first invention is the Fibonacci string. We call a string consisting of only letters $a$ and $b,ドル with exactly $n$ letters $a$ without any two consecutive letters $a$ a Fibonacci string of the $n$:th order.

Given a string $X$ of $a$:s and $b$:s, compute the sum of orders of all Fibonacci strings that are substrings of $X$. Note that if a string $X$ appears multiple times, its order should be counted once for every occurance.

예제

Assume that Aron has the string $abaaba$. This contains the Fibonacci string $a$ four times, $ab$ two times, $ba$ two times and $aba$ two times. The sum of their orders is 4ドル \cdot 1 + 2 \cdot 1 + 2 \cdot 1 + 2 \cdot 2 = 4 +たす 2 +たす 2 +たす 4 = 12$.

구현

Write a program that given $X$ computes the sum of orders of all Fibonacci substrings of $X$. You should implement the function fibonacci(N, X}.

  • fibonacci(N, X) - this function will be called exactly once by the judge.
    • N: an integer - the number of charaters in the string $X$.
    • X: a string consisting of $X$ characters, consisting only lowercase letters $a$ and $b$.
    • The function should return an integer, the sum of orders of all Fibonacci substrings of $X$.

A code skeleton containing the function to be implemented, together with a sample grader, can be found at attachments.zip.

입력

The sample judge reads input in the following format:

  • line 1ドル$: N
  • line 2ドル$: X

출력

The judge writes a single line containing the return value of fibonacci(N, X).

제한

  • 1ドル \le N \le 100,000円$

예제 입력 1

6
abaaba

예제 출력 1

12

힌트

출처

Olympiad > Swedish Olympiad in Informatics > 2016 > KATT3 C번

  • 문제를 만든 사람: Johan Sannemo

제출할 수 있는 언어

C++17, Java 8, C++14, Java 8 (OpenJDK), Java 11, C++20, Java 15, C++14 (Clang), C++17 (Clang), C++20 (Clang)

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /