結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 211 ms
54,972 KB
testcase_01 AC 216 ms
54,912 KB
testcase_02 AC 210 ms
54,924 KB
testcase_03 AC 208 ms
55,096 KB
testcase_04 AC 201 ms
55,032 KB
testcase_05 AC 199 ms
55,148 KB
testcase_06 AC 209 ms
52,864 KB
testcase_07 AC 206 ms
54,828 KB
testcase_08 AC 210 ms
53,004 KB
testcase_09 AC 205 ms
55,468 KB
testcase_10 AC 214 ms
54,924 KB
testcase_11 AC 217 ms
55,348 KB
testcase_12 AC 215 ms
54,928 KB
testcase_13 AC 216 ms
55,216 KB
testcase_14 AC 214 ms
54,976 KB
testcase_15 AC 216 ms
55,140 KB
testcase_16 AC 203 ms
54,916 KB
testcase_17 AC 201 ms
55,040 KB
testcase_18 AC 221 ms
54,892 KB
testcase_19 AC 205 ms
54,800 KB
testcase_20 AC 211 ms
54,964 KB
testcase_21 AC 200 ms
54,828 KB
testcase_22 AC 206 ms
53,332 KB
testcase_23 AC 212 ms
55,044 KB
testcase_24 AC 216 ms
55,464 KB
testcase_25 AC 214 ms
55,028 KB
testcase_26 AC 207 ms
55,044 KB
testcase_27 AC 210 ms
55,140 KB
testcase_28 AC 209 ms
54,972 KB
testcase_29 AC 209 ms
55,036 KB
testcase_30 AC 209 ms
52,868 KB
testcase_31 AC 223 ms
55,068 KB
testcase_32 AC 217 ms
55,520 KB
testcase_33 AC 219 ms
55,632 KB
testcase_34 AC 217 ms
55,208 KB
testcase_35 AC 221 ms
55,416 KB
testcase_36 AC 215 ms
55,216 KB
testcase_37 AC 214 ms
55,600 KB
testcase_38 AC 237 ms
55,792 KB
testcase_39 AC 242 ms
55,400 KB
testcase_40 AC 253 ms
55,408 KB
testcase_41 AC 264 ms
55,248 KB
testcase_42 AC 271 ms
55,356 KB
testcase_43 AC 278 ms
55,548 KB
testcase_44 AC 296 ms
55,400 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] * 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;
        }
    }
}
0