Submission #00064


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<bits/stdc++.h>
using namespace std;
const int M = 1000000007;
long long powmod(long long a, long long b) {
if (b == 0) return 1;
long long t = powmod(a, b / 2);
t = t * t % M;
if (b % 2) t = t * a % M;
return t;
}
long long inv(long long a) {
return powmod(a, M - 2);
}
int main() {
int lim = 1000010;
vector<long long> fact(lim), invfact(lim);
fact[0] = 1;
for (int i = 1; i < lim; ++i) {
fact[i] = fact[i - 1] * i % M;
}
invfact[lim - 1] = inv(fact[lim - 1]);
for (int i = lim - 1; i > 0; --i) {
invfact[i - 1] = invfact[i] * i % M;
}
int h, w, n;
cin >> h >> w >> n;
int px = 0, py = 0;
long long ans = 1;
for (int i = 0; i < n; ++i) {
int x, y;
cin >> x >> y;
int dx = x - px, dy = y - py;
ans = ans * fact[dx + dy] % M * invfact[dx] % M * invfact[dy] % M;
px = x;
py = y;
}
{
int x = h - 1, y = w - 1;
int dx = x - px, dy = y - py;
ans = ans * fact[dx + dy] % M * invfact[dx] % M * invfact[dy] % M;
}
cout << ans << "\n";
return 0;
}

ステータス

項目 データ
問題 0006 - 寄り道
ユーザー名 rian
投稿日時 2018-11-24 14:18:51
言語 C++17
状態 Accepted
得点 400
ソースコード長 1182 Byte
最大実行時間 39 ms
最大メモリ使用量 16220 KB

セット

セット 得点 Cases
1 ALL 400 / 400 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
input01.in AC 34 ms 16220 KB
1
input02.in AC 36 ms 16048 KB
1
input03.in AC 39 ms 16132 KB
1
input04.in AC 32 ms 16088 KB
1
input05.in AC 32 ms 16164 KB
1
input06.in AC 33 ms 16116 KB
1
input07.in AC 30 ms 16200 KB
1
input08.in AC 30 ms 16156 KB
1
input09.in AC 37 ms 16112 KB
1
input10.in AC 34 ms 16200 KB
1
input11.in AC 31 ms 16156 KB
1
input12.in AC 28 ms 16112 KB
1
input13.in AC 29 ms 16192 KB
1
input14.in AC 32 ms 16148 KB
1
input15.in AC 34 ms 16100 KB
1
input16.in AC 29 ms 16180 KB
1
input17.in AC 30 ms 16136 KB
1
input18.in AC 32 ms 16096 KB
1
input19.in AC 36 ms 16052 KB
1
input20.in AC 32 ms 16136 KB
1
sample.in AC 28 ms 16092 KB
1