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

9640번 - Modified LCS 다국어

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

문제

LCS stands for longest common subsequence, and it is a well known problem. A sequence in this problem means a list of integers, and a sequence X is considered a subsequence of another sequence Y, when the sequence X can be obtained by deleting zero or more elements from the sequence Y without changing the order of the remaining elements.

In this problem you are given two sequences and your task is to find the length of the longest sequence which is a subsequence of both the given sequences.

You are not given the sequences themselves. For each sequence you are given three integers N , F and D, where N is the length of the sequence, F is the first element in the sequence. Each element except the first element is greater than the element before it by D.

For example N = 5, F = 3 and D = 4 represents the following sequence: [3, 7, 11, 15, 19].

There will be at least one integer which belongs to both sequences and it is not greater than 1,000,000.

입력

Your program will be tested on one or more test cases. The first line of the input will be a single integer T, the number of test cases (1 ≤ T ≤ 100). Followed by the test cases, each test case is described in one line which contains 6 integers separated by a single space N1 F1 D1 N2 F2 D2 (1 ≤ N1,N2 ≤ 1018) and (1 ≤ F1,D1,F2,D2 ≤ 109) representing the length of the first sequence, the first element in the first sequence, the incremental value of the first sequence, the length of the second sequence, the first element in the second sequence and the incremental value of the second sequence, respectively.

출력

For each test case, print a single line which contains a single integer representing the length of the longest common subsequence between the given two sequences.

제한

예제 입력 1

3
5 3 4 15 3 1
10 2 2 7 3 3
100 1 1 100 1 2

예제 출력 1

4
3
50

힌트

출처

ICPC > Regionals > Africa and Arab > Arab Collegiate Programming Contest > 2013 Arab Collegiate Programming Contest J번

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

출처

대학교 대회

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

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