NOI '13 P4 - Matrix Game

View as PDF

Submit solution

Points: 20 (partial)
Time limit: 0.6s
Memory limit: 256M

Problem type
National Olympiad in Informatics, China, 2013

TingTing is a girl that loves matrices. One day, she wants to use a computer to generate a giant n row by m column matrix (you don't have to worry about how she'll store it). Her generated matrix will satisfy a mystical property: if we use F[i][j] to represent the cell in the i-th row and j-th column, then F[i][j] will satisfy the following system of equations:

{F[1][1]=1F[i][j]=a×F[i][j1]+bj1F[i][1]=c×F[i1][m]+di1

where a, b, c, and d are given constants.

TingTing would like to know the value of F[n][m] and she would like you to help her. Since the final value may be very large, you are only required to output it modulo 1000000007.

Input Specification

The input will contain the six integers n, m, a, b, c, and d.

Output Specification

Output a single integer, the value of F[n][m] modulo 1000000007.

Sample Input

Copy
3 4 1 3 2 6

Sample Output

Copy
85

Explanation

The matrix in the example is:

(147102629323576798285)

Constraints

Test Case Constraints
1 1n,m10; 1a,b,c,d1000
2 1n,m100; 1a,b,c,d1000
3 1n,m103; 1a,b,c,d109
4
5 1n,m109; 1a=c109; 1b=d109
6 1n,m109; a=c=1; 1b,d109
7 1n,m,a,b,c,d109
8
9
10
11 1n,m101000; a=c=1; 1b,d109
12 1n,m101000; 1a=c109; 1b=d109
13 1n,m101000; 1a,b,c,d109
14
15 1n,m1020000; 1a,b,c,d109
16
17 1n,m101000000; a=c=1; 1b,d109
18 1n,m101000000; 1a=c109; 1b=d109
19 1n,m101000000; 1a,b,c,d109
20

Problem translated to English by Alex.


Comments


  • 0
    maxcruickshanks  commented on Aug. 10, 2022, 4:21 a.m.

    Since the original data were weak, two additional test cases were added and weighted identically to the others, and all submissions were rejudged.