結果

問題 No.148 試験監督(3)
ユーザー uwiuwi
提出日時 2015-02-12 17:49:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 694 ms / 1,000 ms
コード長 4,923 bytes
コンパイル時間 3,926 ms
コンパイル使用メモリ 77,208 KB
実行使用メモリ 60,972 KB
最終ジャッジ日時 2023-09-06 00:00:42
合計ジャッジ時間 9,144 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 204 ms
53,256 KB
testcase_01 AC 258 ms
53,288 KB
testcase_02 AC 484 ms
53,408 KB
testcase_03 AC 549 ms
52,756 KB
testcase_04 AC 694 ms
53,140 KB
testcase_05 AC 439 ms
52,848 KB
testcase_06 AC 471 ms
58,200 KB
testcase_07 AC 679 ms
60,972 KB
testcase_08 AC 594 ms
60,768 KB
testcase_09 AC 128 ms
55,272 KB
testcase_10 AC 126 ms
55,208 KB
testcase_11 AC 65 ms
50,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package q3xx;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Q371_4F {
	static InputStream is;
	static PrintWriter out;
	static String INPUT = "";
	
	static final int INTERVAL = 3400000;
	
	static int d(char[] a,int l){int r=0,j=l+4;for(;j>=l;j--)r=r*93+a[j]-(a[j]+1880)/58;return r;}
	static final char[] enigma = "!    CLc!-|k$k-d{e$#OZL0 @x7?$`e4/&1j50)i?(C,'?jW-<0FN'#*7}$5sMq HFc%#ZWcR!9ZM^'c{u|'5.ev*['x]&S^>Z'dhrT%1{-k%2KLX gZ=E-Np6e u*O.({>=H&U3#T'`'Fa!.J=2*^M2O-vQ+]-VT.,&!2($&4kSc$T#^y#PB}j*]r-l*]DSa$M 'W*4/2<&r[;*)ii|n(c'BS*RBRj(E/Q~*o]8--3)>X)VRm=&Fo39)CaTt *<S6)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%&bRM%'|6Aw+tM{8)SR_0+<o-q+/&&Z-PETJ'paqL,jhH|+p.U[)1&vc,Wyk0$_=6g#Nydk)Wduo q'<b(=}z^ *O{% dxdr#[ffc-WOB;!w/OL*d5=@!Us4g%mCrl 3p**&+hTx-)QH%%<NfY%K*U0&u*#8+[pk ,8dhh#s-q6)l,[2#fH~t(".toCharArray();
	static void solve()
	{
		for(int T = ni();T >= 1;T--){
			String C = ns(), P = ns();
			if(P.length() >= 11){
				out.println(0);
				continue;
			}
			long pl = Long.parseLong(P);
			
			if(pl >= mod){
				out.println(0);
				continue;
			}
			
			long cl = 0;
			if(C.length() >= 12){
				for(char x : C.toCharArray())cl = (cl*10+x-'0')%mod;
			}else{
				cl = Long.parseLong(C);
				if(cl-(2*pl-1)+1 <= 0){
					out.println(0);
					continue;
				}
			}
			
			long sup = (cl-(pl-1))%mod;
			long inf = (cl-(2*pl-1))%mod;
			if(inf < 0)inf += mod;
			if(sup < 0)sup += mod;
			if(sup < inf){
				out.println(0);
				continue;
			}
			
			out.println(f((int)sup)*invl(f((int)inf), mod)%mod);
		}
	}
	
	public static long invl(long a, long mod) {
		long b = mod;
		long p = 1, q = 0;
		while (b > 0) {
			long c = a / b;
			long d;
			d = a;
			a = b;
			b = d % b;
			d = p;
			p = q;
			q = d - c * q;
		}
		return p < 0 ? p + mod : p;
	}
	
	static long f(int n)
	{
		int h = n%INTERVAL;
		if(h < INTERVAL/2){
			long mul = d(enigma, n/INTERVAL*5);
			int base = n/INTERVAL*INTERVAL;
			for(int i = base+1;i <= n;i++){
				mul = mul * i % mod;
			}
			return mul;
		}else{
			long mul = 1;
			int base = n/INTERVAL*INTERVAL+INTERVAL;
			for(int i = base;i > n;i--){
				mul = mul * i % mod;
			}
			return invl(mul,mod)*d(enigma, n/INTERVAL*5+5)%mod;
		}
	}
	
	static int mod = 1000000007;
	
	public static void main(String[] args) throws Exception
	{
		long S = System.currentTimeMillis();
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);
		
		solve();
		out.flush();
		long G = System.currentTimeMillis();
		tr(G-S+"ms");
	}
	
	private static byte[] inbuf = new byte[1024];
	static int lenbuf = 0, ptrbuf = 0;
	
	private static int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
	
	private static String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private static int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}
0