問題一覧 > 通常問題

No.612 Move on grid

レベル : / 実行時間制限 : 1ケース 2.500秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 88
作問者 : りあん / テスター : tsutaj
お気に入りにしたユーザー ProblemId : 2004 / 自分の提出
問題文最終更新日: 2026-06-25 07:52:13
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
Advent Calendar Contest 2017 (順位表) の他の問題:

The Usual Note

The intended solution got TLE in Python, so we recommend submitting with PyPy.

Problem Statement

A point $P$ moves on a 3-dimensional grid according to the following rules.

  • Initially, at time 0, the point $P$ is at the origin $(0, \ 0, \ 0)$.
  • When the point $P$ is at the lattice point $(x, \ y, \ z)$ at time $t$, the position of the point $P$ at time $t + 1$ is one of the adjacent lattice points
    • $(x + 1, \ y, \ z)$
    • $(x, \ y + 1, \ z)$
    • $(x, \ y, \ z + 1)$
    • $(x - 1, \ y, \ z)$
    • $(x, \ y - 1, \ z)$
    • $(x, \ y, \ z - 1)$
    and the probability of moving to each of these points is $\displaystyle \frac{1}{6}$.

Let $p$ be the probability that the coordinates $(x, \ y, \ z)$ of the point $P$ at time $T$ satisfy $ \ d \leq ax + by + cz \leq e \ $. Then $6^T \times p$ is an integer.

Find $6^T \times p$ modulo $10^9 + 7$.

Input

$T$
$a$ $b$ $c$ $d$ $e$

The first line contains the time $T$ described in the problem statement.

The second line contains the parameters $a$, $b$, $c$, $d$, $e$ representing the condition in the problem statement, in this order, separated by single spaces.

All inputs are integers and satisfy the following constraints.

  • $1 \leq T \leq 500$
  • $|a|, \ |b|, \ |c| \leq 20$
  • $(a, \ b, \ c) \neq (0, \ 0, \ 0)$
  • $-10000 \leq d \leq e \leq 10000$

Output

Output $6^T \times p$ modulo $10^9 + 7$. Print a newline at the end.

Sample

Sample 1
Input
1
1 0 0 1 1
Output
1

The point must be on the plane $x = 1$ in 3-dimensional space at time 1, so the condition holds when it moves to $(1, 0, 0)$.

The probability is $\displaystyle \frac{1}{6}$, so the answer is $\displaystyle 6 \times \frac{1}{6} = 1$.

Sample 2
Input
3
-2 0 0 -4 2
Output
202

Sample 3
Input
6
1 -1 0 0 0
Output
9024

Sample 4
Input
120
12 -1 2 -1212 1212
Output
504758737

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。