luogu#P5185. [COCI 2009/2010 #3] PLANETE
[COCI 2009/2010 #3] PLANETE
Problem Description
Translated from COCI 2009.12 T6 “PLANETE”.
You are given records. The -th record contains two dates without a year (in other words, only month and day), and an array of length . Find any solution to the system of equations in :
$\begin{cases}A_1+\displaystyle\sum_{j=1}^M a_{1,j}x_j\equiv B_1\pmod{365} \\ A_2+\displaystyle\sum_{j=1}^M a_{2,j}x_j\equiv B_2\pmod{365} \\ \vdots \\ A_N+\displaystyle\sum_{j=1}^M a_{N,j}x_j\equiv B_N\pmod{365}\end{cases}$
If there is no solution, output -1 only.
Input Format
The first line contains two integers .
In the next lines, the -th line starts with four integers, representing: the day of , the month of , the day of , and the month of . Then follow integers representing .
Output Format
If there is a solution, output lines in total. The -th line contains one integer, representing .
If there is no solution, output -1 only.
1 1
26 02 03 03 1
5
1 1
26 02 03 03 2
185
3 3
22 03 01 10 9 10 10
05 05 16 12 1 7 10
20 06 15 01 4 9 10
102
204
125
Hint
Constraints: , . The input months and days are guaranteed to be valid.
Translated by ChatGPT 5