結果

問題 No.147 試験監督(2)
ユーザー kuuso1kuuso1
提出日時 2015-02-10 23:29:25
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 388 ms / 2,000 ms
コード長 5,018 bytes
コンパイル時間 3,064 ms
コンパイル使用メモリ 107,064 KB
実行使用メモリ 27,668 KB
最終ジャッジ日時 2023-09-05 23:04:15
合計ジャッジ時間 5,029 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 385 ms
25,648 KB
testcase_01 AC 384 ms
27,668 KB
testcase_02 AC 388 ms
25,576 KB
testcase_03 AC 51 ms
21,480 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Text;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using BI=System.Numerics.BigInteger;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		Mat[] Fib=new Mat[80];
		Fib[0]=new Mat(1,0,0,1);
		Fib[1]=new Mat(1,1,1,0);
		for(int i=2;i<80;i++)Fib[i]=Fib[i-1]*Fib[i-1];
		long Ans=1;
		
		for(int i=0;i<N;i++){
			long val=1;
			if(C[i]==1)val=2;
			if(C[i]==2)val=3;
			if(C[i]>2){
				long t=C[i]-2;
				Mat E=new Mat(1,0,0,1);
//Console.WriteLine(E.a+" "+E.b+" "+E.c+" "+E.d);
				for(int ii=1;ii<61;ii++){
					if(((t>>(ii-1))&1)>0){
						E=E*Fib[ii];
//Console.WriteLine(E.a+" "+E.b+" "+E.c+" "+E.d);
					}
				}
				val=(E.a*3+E.b*2)%mod;
			}
//Console.WriteLine(val);			
			long tot=1;
			if(val==0)tot=0;
			long[] xx=new long[61];
			xx[0]=1;
			xx[1]=val;
			for(int ii=2;ii<61;ii++){
				xx[ii]=(xx[ii-1]*xx[ii-1])%mod;
			}
			for(int ii=1;ii<61;ii++){
				if(D[i]%2==1){
					tot*=xx[ii];
					tot%=mod;
				}
				D[i]/=2;
			}
			Ans*=tot;
			Ans%=mod;
		}
		Console.WriteLine(Ans);
	}
	
	
	class Mat{
		public long a,b,c,d;
		public Mat(long aa,long bb,long cc,long dd){
			a=aa;b=bb;c=cc;d=dd;
		}
		public static Mat operator*(Mat x,Mat y){
			return new Mat(	((x.a*y.a)%mod+(x.b*y.c)%mod)%mod,
					((x.a*y.b)%mod+(x.b*y.d)%mod)%mod,
					((x.c*y.a)%mod+(x.d*y.c)%mod)%mod,
					((x.c*y.b)%mod+(x.d*y.d)%mod)%mod );
		}
	}

	static long mod=(long)(1e9+7);
	
	int N;
	long[] C;
	long[] D;
	FastIn rd;
	
	public Sol(){
		rd=new FastIn(1000000);
		N=rd.ReadInt();
		C=new long[N];
		D=new long[N];
		for(int i=0;i<N;i++){
			C[i]=rd.ReadLong();
			D[i]=rd.ReadLongMod();
		}
		rd.Dispose();
	}




}

class FastIn:IDisposable {
	static long mod=(long)(1e9+7);

	int Size;
	byte[] Mem;
	int ptr;
	int rsize;
	bool unfinished;
	Stream stdin;
	void Init(int n) {
		Size = n;
		Mem = new byte[Size];
		rsize=(stdin=Console.OpenStandardInput()).Read(Mem, 0, Size);
		ptr = 0;
		unfinished=(rsize == Size);
	}
	void Next() {
		if (unfinished == false) return;
		rsize=stdin.Read(Mem, 0, Size);
		ptr = 0;
		unfinished = (rsize == Size);
	}
	
	~FastIn(){
		stdin.Dispose();
	}
	void IDisposable.Dispose(){
		stdin.Dispose();
	}
	public void Dispose(){
		stdin.Dispose();
	}
	
	public FastIn() {
		Init(100000);
	}
	public FastIn(int n) {
		Init(n);
	}
	public int ReadInt() {
		int ret = 0;
		int sig = 1;
		while (ptr < rsize && Mem[ptr] != ' ' && Mem[ptr] != '\n' && Mem[ptr] != '\r' ) {
			if(ret==0 && Mem[ptr] == '-'){
				sig *= -1; ptr++; continue;
			}
			ret = ret * 10 + Mem[ptr++] - '0';
			if (ptr == Size) Next();
		}
		while (ptr < rsize && (Mem[ptr] == ' ' || Mem[ptr] == '\n' || Mem[ptr] == '\r') ) {
			ptr++;
			if (ptr == Size) Next();
		}
		return ret*sig;
	}
	public long ReadLong() {
		long ret = 0;
		long sig = 1;
		while (ptr < rsize && Mem[ptr] != ' ' && Mem[ptr] != '\n' && Mem[ptr] != '\r' ) {
			if(ret==0 && Mem[ptr] == '-'){
				sig *= -1; ptr++; continue;
			}
			ret = ret * 10 + Mem[ptr++] - '0';
			if (ptr == Size) Next();
		}
		while (ptr < rsize &&  (Mem[ptr] == ' ' || Mem[ptr] == '\n' || Mem[ptr] == '\r')  ) {
			ptr++;
			if (ptr == Size) Next();
		}
		return ret*sig;
	}
	public long ReadLongMod() {
		long ret = 0;
		long sig = 1;
		while (ptr < rsize && Mem[ptr] != ' ' && Mem[ptr] != '\n' && Mem[ptr] != '\r' ) {
			if(ret==0 && Mem[ptr] == '-'){
				sig *= -1; ptr++; continue;
			}
			ret = (ret * 10 + Mem[ptr++] - '0')%(mod-1);
			if (ptr == Size) Next();
		}
		while (ptr < rsize &&  (Mem[ptr] == ' ' || Mem[ptr] == '\n' || Mem[ptr] == '\r')  ) {
			ptr++;
			if (ptr == Size) Next();
		}
		return ret*sig;
	}
	public BI ReadBI() {
		BI ret = 0;
		BI sig = 1;
		while (ptr < rsize && Mem[ptr] != ' ' && Mem[ptr] != '\n' && Mem[ptr] != '\r' ) {
			if(ret==0 && Mem[ptr] == '-'){
				sig *= -1; ptr++; continue;
			}
			ret = ret * 10 + Mem[ptr++] - '0';
			if (ptr == Size) Next();
		}
		while (ptr < rsize &&  (Mem[ptr] == ' ' || Mem[ptr] == '\n' || Mem[ptr] == '\r')  ) {
			ptr++;
			if (ptr == Size) Next();
		}
		return ret*sig;
	}
	public String ReadStr() {
		//2byte文字はNG
		StringBuilder sb = new StringBuilder();
		while (ptr < rsize && Mem[ptr] != ' ' && Mem[ptr] != '\n' && Mem[ptr] != '\r') {
			sb.Append((char)Mem[ptr++]);
			if (ptr == Size && unfinished) Next();
		}
		while (ptr < rsize &&  (Mem[ptr] == ' ' || Mem[ptr] == '\n' || Mem[ptr] == '\r') ) {
			ptr++;
			if (ptr == Size && unfinished) Next();
		}
		return sb.ToString();
	}
	public String ReadLine() {
		//極力使わない(split/parseするくらいなら上をつかう)
		StringBuilder sb = new StringBuilder();
		while (ptr < rsize && Mem[ptr] != '\n' && Mem[ptr] != '\r') {
			sb.Append((char)Mem[ptr++]);
			if (ptr == Size && unfinished) Next();
		}
		while (ptr < rsize &&  (Mem[ptr] == ' ' || Mem[ptr] == '\n' || Mem[ptr] == '\r')) {
			ptr++;
			if (ptr == Size && unfinished) Next();
		}
		return sb.ToString();
	}
}
0