P23719 [AtCoder] [ABC024D] Dynamic Programming
提高
题目描述

Problem Description

(21:52) It has been discovered that one of the sample test cases used in the judge differs from the one in the problem statement. We apologize for the inconvenience. Please note that the test case itself is correct, so there will be no rejudging. Takahashi decided to solve the following problem using a grid paper that has $10^8$ squares both vertically and horizontally.

"Starting from the bottom-leftmost square, repeatedly move one square to the right or one square up, and find the number of ways to reach each square, modulo $1,000,000,007$."

Takahashi loves dynamic programming and quickly realized that this problem can be solved using dynamic programming.

Specifically,

  1. Write $1$ in all squares belonging to the leftmost column or the bottommost row.
  2. For squares that do not yet have an integer written, if both the square to the left and the square below have integers written, write the sum of these two integers modulo $1,000,000,007$ in the square.
  3. Repeat step 2 until there are no more squares without an integer written.

Takahashi filled all the squares with the "number of ways to reach from the bottom-left, modulo $1,000,000,007$" using the above algorithm.

The bottom-left part of the finished grid paper looks like the figure below.

However, after finishing the writing, he got so overwhelmed with a sense of accomplishment that he tore a part of the grid paper.

Takahashi has a fragment of the grid paper that contains the numbers written in a certain square and the squares above and to the right of it.

Takahashi wants to put this fragment back to its original position, but the grid paper is too large, and he doesn't know where to place it.

From the information on the fragment, determine the position from the left and from the bottom where this fragment originally was.

That is, denoting the square $x$ squares from the left and $y$ squares from the bottom as $(x, y)$, given the integers written in the squares $(r, c)$, $(r, c + 1)$, and $(r + 1, c)$, find $r$ and $c$.

Note that the bottom-leftmost square is $(0, 0)$.

Input Format

The input is given from the standard input in the following format:

$ A $ $ B $ $ C $

  • The first line contains the integer $A$ written in the square $(r, c) (0 ≦ A < 1,000,000,007)$.
  • The second line contains the integer $B$ written in the square $(r, c + 1) (0 ≦ B < 1,000,000,007)$.
  • The third line contains the integer $C$ written in the square $(r + 1, c) (0 ≦ C < 1,000,000,007)$.
  • There exists a solution such that $0 ≦ r, c < 99,999,999$ for the given $A, B, C$.

Output Format

Output the two integers $r (0 ≦ r < 99,999,999)$ and $c (0 ≦ c < 99,999,999)$ representing the original position of the fragment, separated by a space. If there are multiple possible answers for $r, c$, output the one with the smallest $r$. If there are still multiple answers, output the one with the smallest $c$ among those with the smallest $r$. End the output with a newline.

Sample Input and Output

Sample Input #1

15
35
21

Sample Output #1

4 2

Sample Input #2

126
252
210

Sample Output #2

5 4

Sample Input #3

144949225
545897619
393065978

Sample Output #3

314159 365358

Notes/Hints

Sample Explanation 1

The fragment in Takahashi's hand looks like the figure below. [MATH0]

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
15 35 21
样例输出
4 2