結果
| 問題 |
No.147 試験監督(2)
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-04-20 01:01:19 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 3,865 bytes |
| コンパイル時間 | 1,742 ms |
| コンパイル使用メモリ | 111,780 KB |
| 実行使用メモリ | 823,668 KB |
| 最終ジャッジ日時 | 2024-10-04 14:16:36 |
| 合計ジャッジ時間 | 4,222 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | MLE * 1 -- * 3 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
class Program
{
public void Proc()
{
Reader.IsDebug = false;
int deskKindCOunt = int.Parse(Reader.ReadLine());
long ans = 1;
for(int i=0; i<deskKindCOunt; i++) {
string[] inpt = Reader.ReadLine().Split(' ');
long isuCount = long.Parse(inpt[0]);
String mul = inpt[1];
long kumiawase = this.GetKumiawase(isuCount);
long subAns = Calc(kumiawase, mul);
ans *= subAns;
ans = ans % baseNum;
}
Console.WriteLine(ans);
}
private long Calc(long num, string mp) {
string subMp = mp;
long ans = 1;
while (subMp.Length > 10)
{
long mul = long.Parse(subMp.Substring(subMp.Length - 10));
ans *= this.Pow(num, mul);
ans = ans % baseNum;
ans *= this.Pow(num, 10000000000);
ans = ans % baseNum;
subMp = subMp.Substring(0, subMp.Length - 10);
}
ans *= this.Pow(num, long.Parse(subMp));
ans = ans % baseNum;
return ans;
}
private long Pow(long num , long pow) {
if(!powerDic.ContainsKey(num)) {
powerDic.Add(num, new Dictionary<long, long>());
}
if(powerDic[num].ContainsKey(pow)) {
return powerDic[num][pow];
}
long ans = 1;
if(pow == 0) {
return 1;
}
if(pow == 1) {
return num;
}
if(pow == 2) {
return (num * num) % baseNum;
}
long subPow = pow / 2;
ans *= this.Pow(num, subPow);
ans *= this.Pow(num, pow - subPow);
ans = ans % baseNum;
powerDic[num].Add(pow, ans);
return ans;
}
private long GetKumiawase(long remainIsu) {
if(dic.ContainsKey(remainIsu)) {
return dic[remainIsu];
}
if(remainIsu == 1) {
return 2;
}
if(remainIsu == 0) {
return 0;
}
long ret1 = this.GetKumiawase(remainIsu - 1);
long ret2 = 0;
if(remainIsu == 2) {
ret2 += 1;
} else if(remainIsu > 2) {
ret2 = this.GetKumiawase(remainIsu - 2);
}
long ans = (ret1 + ret2) % baseNum;
dic.Add(remainIsu, ans);
return ans;
}
private Dictionary<long, Dictionary<long, long>> powerDic = new Dictionary<long, Dictionary<long, long>>();
private long baseNum = 1000000000 + 7;
private Dictionary<long, long> dic = new Dictionary<long, long>();
public class Reader
{
public static bool IsDebug = true;
private static String PlainInput = @"
3
10 10
20 20
30 30
";
private static System.IO.StringReader Sr = null;
public static string ReadLine()
{
if (IsDebug)
{
if (Sr == null)
{
Sr = new System.IO.StringReader(PlainInput.Trim());
}
return Sr.ReadLine();
}
else
{
return Console.ReadLine();
}
}
public static int[] GetInt(char delimiter = ' ', bool trim = false)
{
string inptStr = ReadLine();
if (trim)
{
inptStr = inptStr.Trim();
}
string[] inpt = inptStr.Split(delimiter);
int[] ret = new int[inpt.Length];
for (int i = 0; i < inpt.Length; i++)
{
ret[i] = int.Parse(inpt[i]);
}
return ret;
}
}
static void Main()
{
Program prg = new Program();
prg.Proc();
}
}
14番