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

30321번 - Cutting into Monotone Increasing Sequence 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 (추가 시간 없음) 1024 MB175454032.258%

문제

A monotone sequence is a sequence of numbers that either consistently increases or consistently decreases as you move along the sequence. In other words, it exhibits a consistent trend in either an upward or downward direction.

In a monotone increasing sequence, each term in the sequence is greater than or equal to the preceding term. Mathematically, for a sequence $a_1, \dots , a_n,ドル it is monotone increasing if and only if for every 1ドル≤ i < n,ドル $a_i ≤ a_{i+1}$. For example, the sequence 1,2,2,4,5ドル$ is a monotone increasing sequence because each term is greater than or equal to the previous term.

Monotone sequences are important in various areas of mathematics, including calculus and analysis, as they often simplify the analysis of functions and their behavior. They provide a clear and consistent trend that makes it easier to understand the behavior of a sequence or a function over a range of values.

One of our problem setters is fond of big integers. Over the past few years, the Taiwan Online Programming Contest has frequently featured problems involving big integers. This time, we have a problem that combines big integers with monotone increasing sequences. Your task is to transform a big integer, denoted as $x,ドル into a monotone increasing sequence by inserting commas ',' into the gaps between its digits, while adhering to following constraints.

  • The last term of the monotone increasing sequence is no more than $b$.
  • Commas cannot be inserted before a zero.
  • The number of commas is minimized.

Let's assume that $x$ is an integer with $k$ digits and is represented as $d_1d_2\cdots d_k$. For instance, if we have $x=654321=d_1d_2 \cdots d_6$ and $b=1000,ドル we can insert commas into gaps after $d_3$ and $d_5$ to convert $x$ into the following monotone increasing sequence: 6,54,321ドル$.

Please write a program to compute the minimum number of commas required to transform a given big integer $x$ into a monotone increasing sequence consisting of numbers no more than a given integer $b$. If there is no way to transform, please print 'NO WAY'.

입력

The input contains two non-negative integers $x$ and $b$.

출력

Print the minimum number of commas required to transform $x$ into a monotone increasing sequence consisting of numbers no more than $b$. If there is no way to transform, please print 'NO WAY' without quotes.

제한

  • $x≤10^{100000}$
  • $b<2^{64}$
  • There is no leading zero if $x>0$.

예제 입력 1

654321 1000

예제 출력 1

2

예제 입력 2

654321 100

예제 출력 2

NO WAY

힌트

출처

ICPC > Regionals > Asia Pacific > Taiwan > Taiwan Online Programming Contest > TOPC 2023 C번

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

출처

대학교 대회

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

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