結果

問題 No.895 MESE
ユーザー kitakitalilykitakitalily
提出日時 2019-09-28 14:02:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 186 ms / 2,000 ms
コード長 4,965 bytes
コンパイル時間 2,296 ms
コンパイル使用メモリ 77,732 KB
実行使用メモリ 62,644 KB
最終ジャッジ日時 2024-04-10 02:22:31
合計ジャッジ時間 7,855 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
62,564 KB
testcase_01 AC 123 ms
62,448 KB
testcase_02 AC 124 ms
62,644 KB
testcase_03 AC 126 ms
62,548 KB
testcase_04 AC 122 ms
62,612 KB
testcase_05 AC 125 ms
62,508 KB
testcase_06 AC 123 ms
62,540 KB
testcase_07 AC 122 ms
62,508 KB
testcase_08 AC 124 ms
62,608 KB
testcase_09 AC 124 ms
62,476 KB
testcase_10 AC 126 ms
62,564 KB
testcase_11 AC 124 ms
62,504 KB
testcase_12 AC 121 ms
62,284 KB
testcase_13 AC 143 ms
62,612 KB
testcase_14 AC 174 ms
62,272 KB
testcase_15 AC 181 ms
62,572 KB
testcase_16 AC 160 ms
62,552 KB
testcase_17 AC 131 ms
62,288 KB
testcase_18 AC 182 ms
62,528 KB
testcase_19 AC 183 ms
62,528 KB
testcase_20 AC 181 ms
62,572 KB
testcase_21 AC 180 ms
62,544 KB
testcase_22 AC 180 ms
62,544 KB
testcase_23 AC 183 ms
62,636 KB
testcase_24 AC 184 ms
62,560 KB
testcase_25 AC 182 ms
62,504 KB
testcase_26 AC 179 ms
62,564 KB
testcase_27 AC 182 ms
62,532 KB
testcase_28 AC 186 ms
62,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
	static long mod = 1000000007;
	static long INF = 1000000000000L;
	static int size = 600000;
	static long[] fac = new long[size];
	static long[] finv = new long[size];
	static long[] inv = new long[size];
 	public static void main(String[] args){
		FastScanner scanner = new FastScanner();
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		initComb();
		long ans = 0;
		for(int i = 1; i <= a; i++){
			long p = 0;
			long q = 0;
			p = comb(a+b+c-i-2,c-1)%mod*comb(a+b-i-1,b-1);
			p %= mod;
			q = pow(2,a+b+c-i-1)-1;
			ans += p*q%mod;
			ans %= mod;
		}
		System.out.println(ans);
	}
	public static long pow(long x, long n){
    long ans = 1;
    while(n > 0){
      if((n & 1) == 1){
        ans = ans * x;
        ans %= mod;
      }
      x = x * x % mod;
      n >>= 1;
    }
    return ans;
  }

	  //fac, inv, finvテーブルの初期化、これ使う場合はinitComb()で初期化必要
		public static  void initComb(){
			fac[0] = finv[0] = inv[0] = fac[1] = finv[1] = inv[1] = 1;
			for (int i = 2; i < size; ++i) {
				fac[i] = fac[i - 1] * i % mod;
				inv[i] = mod - (mod / i) * inv[(int) (mod % i)] % mod;
				finv[i] = finv[i - 1] * inv[i] % mod;
			}
		}

		//nCk % mod
		public static long comb(int n, int k){
			return fac[n] * finv[k] % mod * finv[n - k] % mod;
		}

		//n! % mod
		public static long fact(int n){
			return fac[n];
		}
	static class Pair implements Comparable<Pair>{
    int first, second;
    Pair(int a, int b){
        first = a;
        second = b;
    }
    @Override
    public boolean equals(Object o){
        if (this == o) return true;
        if (!(o instanceof Pair)) return false;
        Pair p = (Pair) o;
        return first == p.first && second == p.second;
    }
    @Override
    public int compareTo(Pair p){
        //return first == p.first ? second - p.second : first - p.first; //firstで昇順にソート
        //return (first == p.first ? second - p.second : first - p.first) * -1; //firstで降順にソート
        //return second == p.second ? first - p.first : second - p.second;//secondで昇順にソート
        //return (second == p.second ? first - p.first : second - p.second)*-1;//secondで降順にソート
		    //return first * 1.0 / second > p.first * 1.0 / p.second ? 1 : -1; // first/secondの昇順にソート
		    //return first * 1.0 / second < p.first * 1.0 / p.second ? 1 : -1; // first/secondの降順にソート
				//return second * 1.0 / first > p.second * 1.0 / p.first ? 1 : -1; // second/firstの昇順にソート
		    //return second * 1.0 / first < p.second * 1.0 / p.first ? 1 : -1; // second/firstの降順にソート
				//return Math.atan2(second, first) > Math.atan2(p.second, p.first) ? 1 : -1; // second/firstの昇順にソート
				//return first + second > p.first + p.second ? 1 : -1; //first+secondの昇順にソート
				//return first + second < p.first + p.second ? 1 : -1; //first+secondの降順にソート
				return first - second < p.first - p.second ? 1 : -1; //first-secondの降順にソート
		}
  }

	private static class FastScanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
				if (ptr < buflen) {
						return true;
				}else{
						ptr = 0;
						try {
								buflen = in.read(buffer);
						} catch (IOException e) {
								e.printStackTrace();
						}
						if (buflen <= 0) {
								return false;
						}
				}
				return true;
		}
		private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
		private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
		public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
		public String next() {
				if (!hasNext()) throw new NoSuchElementException();
				StringBuilder sb = new StringBuilder();
				int b = readByte();
				while(isPrintableChar(b)) {
						sb.appendCodePoint(b);
						b = readByte();
				}
				return sb.toString();
		}
		public long nextLong() {
				if (!hasNext()) throw new NoSuchElementException();
				long n = 0;
				boolean minus = false;
				int b = readByte();
				if (b == '-') {
						minus = true;
						b = readByte();
				}
				if (b < '0' || '9' < b) {
						throw new NumberFormatException();
				}
				while(true){
						if ('0' <= b && b <= '9') {
								n *= 10;
								n += b - '0';
						}else if(b == -1 || !isPrintableChar(b)){
								return minus ? -n : n;
						}else{
								throw new NumberFormatException();
						}
						b = readByte();
				}
		}
		public int nextInt() {
				long nl = nextLong();
				if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
				return (int) nl;
		}
		public double nextDouble() { return Double.parseDouble(next());}
	}
}
0