結果
問題 | No.147 試験監督(2) |
ユーザー | kuuso1 |
提出日時 | 2015-02-10 23:29:25 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 361 ms / 2,000 ms |
コード長 | 5,018 bytes |
コンパイル時間 | 1,843 ms |
コンパイル使用メモリ | 109,412 KB |
実行使用メモリ | 26,552 KB |
最終ジャッジ日時 | 2024-06-23 18:24:18 |
合計ジャッジ時間 | 3,295 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 357 ms
22,776 KB |
testcase_01 | AC | 361 ms
22,768 KB |
testcase_02 | AC | 360 ms
26,552 KB |
testcase_03 | AC | 24 ms
18,816 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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(); } }