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

18591번 - Faraway 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB32111140.741%

문제

A squad of n soldiers is dispatched to somewhere in Byteland. Currently, i-th soldier is at location (xi, yi). The soldiers are going to set off now, but the target location is not so clear.

Assume the target location is at (xe, ye). It is clear for all soldiers that xe and ye are both non-negative integers within the range [0, m]. Apart from that, for i-th soldier, the only thing he knows is that (|xi − xe| + |yi − ye|) mod ki = ti.

To find the correct target location, these soldiers are working on the information they have now. Please write a program to figure out the number of possible target locations.

입력

The first line of the input contains an integer T (1 ≤ T ≤ 10), denoting the number of test cases.

Each test case starts with a line containing two integers n and m (1 ≤ n ≤ 10, 1 ≤ m ≤ 109), denoting the number of soldiers and the upper bound for xe and ye.

Each of the next n lines contains four integers, xi, yi, ki, and ti (0 ≤ xi, yi ≤ m, 2 ≤ ki ≤ 5, 0 ≤ ti < ki), denoting what i-th soldier knows.

출력

For each test case, print a single line containing a single integer: the number of possible target locations.

제한

예제 입력 1

2
2 5
1 2 4 2
3 1 2 1
2 5
1 2 4 2
1 2 4 3

예제 출력 1

10
0

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2019 > Day 1: Songyang Chen Contest 2 F번

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

출처

대학교 대회

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

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