結果
| 問題 |
No.660 家を通り過ぎないランダムウォーク問題
|
| ユーザー |
夕叢霧香(ゆうむらきりか)
|
| 提出日時 | 2018-01-16 01:44:37 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 342 ms / 2,000 ms |
| コード長 | 2,701 bytes |
| コンパイル時間 | 2,456 ms |
| コンパイル使用メモリ | 77,480 KB |
| 実行使用メモリ | 55,756 KB |
| 最終ジャッジ日時 | 2024-12-24 03:49:38 |
| 合計ジャッジ時間 | 15,956 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 45 |
ソースコード
import java.io.*;
import java.util.*;
class Main {
static final long MOD=1000000007;
static final int N=400000;
static long[] fact;
static long[] invfact;
static void initialize() {
fact = new long[N];
invfact = new long[N];
fact[0] = invfact[0] = 1;
for (int i = 1; i < N; ++i) {
fact[i] = (i * fact[i - 1]) % MOD;
invfact[i] = powerMod(fact[i], MOD - 2);
}
}
static long powerMod(long x, long exponent) {
long prod = 1;
for (int i = 63; i >= 0; --i) {
prod = (prod * prod) % MOD;
if ((exponent & 1L << i) != 0) {
prod = (prod * x) % MOD;
}
}
return prod;
}
static long comb(int x, int y) {
if (x < 0) {
return 0;
}
if (y < 0 || y > x) {
return 0;
}
long r= (fact[x] * powerMod((fact[x - y] * fact[y]) % MOD, MOD - 2)) % MOD;
return r;
}
static long f(int x,int y){
if((x+y)%2!=0)return 0;
return comb(x,(x+y)/2);
}
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
initialize();
int n=sc.nextInt();
long ans=0;
for(int i=n-1;i<=2*n-1;i+=2){
ans+=f(i,n-1)-f(i,n+1)+MOD;
ans%=MOD;
}
out.println(ans);
out.close();
}
// http://codeforces.com/blog/entry/7018
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] nextIntArray(int n){
int[]r=new int[n];
for(int i=0;i<n;++i)r[i]=nextInt();
return r;
}
}
}
夕叢霧香(ゆうむらきりか)