結果

問題 No.250 atetubouのzetubou
ユーザー Grenache
提出日時 2015-07-24 23:46:49
言語 Java
(openjdk 23)
結果
AC  
実行時間 2,026 ms / 5,000 ms
コード長 2,338 bytes
コンパイル時間 3,762 ms
コンパイル使用メモリ 78,640 KB
実行使用メモリ 102,412 KB
最終ジャッジ日時 2024-07-16 00:30:58
合計ジャッジ時間 29,054 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Iterator;


public class Main_yukicoder250 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        preCombiLong(3000);
    	int q = sc.nextInt();
        for (int i = 0; i < q; i++) {
        	int d = sc.nextInt();
        	int x = sc.nextInt();
        	long t = sc.nextLong();

        	try {
        		if (combinationLong(x + d - 1, x) <= t) {
        			System.out.println("AC");
        		} else {
        			System.out.println("ZETUBOU");
        		}
        	} catch (RuntimeException e) {
        		System.out.println("ZETUBOU");
        	}
        }

        sc.close();
    }

	private static long[][] cacheLong;

	private static void preCombiLong(int size) {
		// cache size need size * size * 4.
		// size : ~3000
		cacheLong = new long[size + 1][];
		for (int i = 0; i <= size; i++) {
			cacheLong[i] = new long[i + 1];
			cacheLong[i][0] = 1;
			cacheLong[i][i] = 1;
		}
	}

	private static long combinationLong(int n, int r) {
		r = Math.min(n - r, r);

		if (cacheLong[n][r] == 0) {
			cacheLong[n][r] = combinationLong(n - 1, r) + combinationLong(n - 1, r - 1);
		}

		if (cacheLong[n][r] < 0) {
			throw new RuntimeException("Long Overflow!");
		}
		
		return cacheLong[n][r];
	}

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;
		Iterator<String> it;
		
		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}
		
		String next() throws RuntimeException  {
			try {
				if (it == null || !it.hasNext()) {
					it = Arrays.asList(br.readLine().split(" ")).iterator();
				}
				return it.next();
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}
		
		int nextInt() throws RuntimeException {
			return Integer.parseInt(next());
		}

		long nextLong() throws RuntimeException {
			return Long.parseLong(next());
		}

		float nextFloat() throws RuntimeException {
			return Float.parseFloat(next());
		}

		double nextDouble() throws RuntimeException {
			return Double.parseDouble(next());
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new IllegalStateException();
			}
		}
	}
}
0