結果

問題 No.660 家を通り過ぎないランダムウォーク問題
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2018-01-16 02:09:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 228 ms / 2,000 ms
コード長 2,687 bytes
コンパイル時間 1,960 ms
コンパイル使用メモリ 74,388 KB
実行使用メモリ 55,400 KB
最終ジャッジ日時 2023-08-25 18:03:52
合計ジャッジ時間 12,790 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 201 ms
55,028 KB
testcase_01 AC 202 ms
53,324 KB
testcase_02 AC 202 ms
55,348 KB
testcase_03 AC 201 ms
55,004 KB
testcase_04 AC 206 ms
55,156 KB
testcase_05 AC 203 ms
55,032 KB
testcase_06 AC 200 ms
54,960 KB
testcase_07 AC 202 ms
55,208 KB
testcase_08 AC 200 ms
55,024 KB
testcase_09 AC 205 ms
55,132 KB
testcase_10 AC 217 ms
55,036 KB
testcase_11 AC 206 ms
55,080 KB
testcase_12 AC 201 ms
55,080 KB
testcase_13 AC 207 ms
54,960 KB
testcase_14 AC 205 ms
55,016 KB
testcase_15 AC 207 ms
55,024 KB
testcase_16 AC 202 ms
55,140 KB
testcase_17 AC 202 ms
55,016 KB
testcase_18 AC 201 ms
55,016 KB
testcase_19 AC 196 ms
55,020 KB
testcase_20 AC 196 ms
54,888 KB
testcase_21 AC 211 ms
55,348 KB
testcase_22 AC 205 ms
54,976 KB
testcase_23 AC 209 ms
55,028 KB
testcase_24 AC 198 ms
54,832 KB
testcase_25 AC 210 ms
55,104 KB
testcase_26 AC 205 ms
55,120 KB
testcase_27 AC 205 ms
55,336 KB
testcase_28 AC 208 ms
55,044 KB
testcase_29 AC 211 ms
54,816 KB
testcase_30 AC 212 ms
54,988 KB
testcase_31 AC 207 ms
54,916 KB
testcase_32 AC 212 ms
54,784 KB
testcase_33 AC 202 ms
54,900 KB
testcase_34 AC 204 ms
55,400 KB
testcase_35 AC 212 ms
54,824 KB
testcase_36 AC 207 ms
55,032 KB
testcase_37 AC 207 ms
54,832 KB
testcase_38 AC 228 ms
54,924 KB
testcase_39 AC 223 ms
54,828 KB
testcase_40 AC 203 ms
55,080 KB
testcase_41 AC 214 ms
54,984 KB
testcase_42 AC 215 ms
55,048 KB
testcase_43 AC 215 ms
54,824 KB
testcase_44 AC 215 ms
55,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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] * (invfact[x - y] * invfact[y] % MOD) % 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;
        }
    }
}
0