結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
55,112 KB
testcase_01 AC 68 ms
54,888 KB
testcase_02 AC 71 ms
54,940 KB
testcase_03 AC 70 ms
54,940 KB
testcase_04 AC 68 ms
54,944 KB
testcase_05 AC 70 ms
55,256 KB
testcase_06 AC 68 ms
55,120 KB
testcase_07 AC 69 ms
55,424 KB
testcase_08 AC 70 ms
55,228 KB
testcase_09 AC 68 ms
55,132 KB
testcase_10 AC 69 ms
54,880 KB
testcase_11 AC 68 ms
55,032 KB
testcase_12 AC 70 ms
55,008 KB
testcase_13 AC 67 ms
55,344 KB
testcase_14 AC 68 ms
55,488 KB
testcase_15 AC 67 ms
55,124 KB
testcase_16 AC 69 ms
54,940 KB
testcase_17 AC 68 ms
55,212 KB
testcase_18 AC 68 ms
54,968 KB
testcase_19 AC 67 ms
55,208 KB
testcase_20 AC 68 ms
55,184 KB
testcase_21 AC 69 ms
55,348 KB
testcase_22 AC 70 ms
55,004 KB
testcase_23 AC 68 ms
54,964 KB
testcase_24 AC 69 ms
54,940 KB
testcase_25 AC 68 ms
55,120 KB
testcase_26 AC 71 ms
54,968 KB
testcase_27 AC 71 ms
55,112 KB
testcase_28 AC 69 ms
53,420 KB
testcase_29 AC 71 ms
55,012 KB
testcase_30 AC 70 ms
55,744 KB
testcase_31 AC 70 ms
55,416 KB
testcase_32 AC 76 ms
55,476 KB
testcase_33 AC 73 ms
55,148 KB
testcase_34 AC 74 ms
54,944 KB
testcase_35 AC 75 ms
55,524 KB
testcase_36 AC 77 ms
55,120 KB
testcase_37 AC 74 ms
55,200 KB
testcase_38 AC 76 ms
53,496 KB
testcase_39 AC 76 ms
55,072 KB
testcase_40 AC 77 ms
55,344 KB
testcase_41 AC 81 ms
55,124 KB
testcase_42 AC 82 ms
55,308 KB
testcase_43 AC 81 ms
55,120 KB
testcase_44 AC 81 ms
55,228 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[N-1]=powerMod(fact[N-1],MOD-2);
        for(int i=N-2;i>=0;--i)
	    invfact[i] = invfact[i+1]*(i+1)%MOD;
    }
    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