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

5718번 - Abwords 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB102133.333%

문제

We call “word” every string, containing two or more capital letters A and B, starting with A. We define upon each word the following two actions, resulting in another word:

  • R1: We keep all the letters untouched, except for the last one, which is changed: А becomes B and vice versa – B becomes A.
  • R2: Let’s denote the starting word with w. We form a new word t out of w in the following way:
    • The first letter of t is A, of course.
    • Each next letter at position i (i > 1) ti depends on the letters at positions i-1 and i in the original word w, namely: if wi-1 = wi, we make ti = B; otherwise ti = A.
    • We replace w by t.

The N-time consecutive applying of actions of type R1 and R2 in some order, starting with a given word w is called “N- transformation” of w if:

  • After the application of these actions the resulting word tallies with the given one (w);
  • All words received in between, in the transformation process, are different from one another and differ from the given word, too.

Consider a positive integer N, greater than 1. Write a program abwords, which finds out one word with as few letters as possible, which can be a start of an N-transformation, or ascertains that such word does not exist.

입력

One positive integer N > 1 is read from the standard input.

출력

The program should write to the standard output:

  • Line 1: one word with as few letters as possible, for which an N- transformation exists;
  • Line 2: a string of N characters, each 1 or 2 with no delimiters. This should be the string of the rule numbers in the N-transformation. Applying all of them in the output order starting with the word in output line 1 should lead to its first reproduction without repeating words in the meantime.

Or

  • One line with the message NO if such word does not exist.

제한

  • 2 ≤ N ≤ 100 000

예제 입력 1

6

예제 출력 1

AABB
221212

힌트

There is no word shorter than 4 letters that can start a sequence of 6 actions which reproduce it without repeating words in the meantime. On the other hand, for example, the word AABB with four letters has such sequence of actions (i.e., a 6-transformation for it exists):

AABB --2-> ABAB --2-> AAAA --1-> AAAB --2-> ABBA --1-> ABBA --2-> ABBB --2-> AABB

출처

Olympiad > International Autumn Tournament in Informatics > 2014 > Group A (Seniors) 2번

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

출처

대학교 대회

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

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