結果
| 問題 |
No.1073 無限すごろく
|
| コンテスト | |
| ユーザー |
Yusei Kato
|
| 提出日時 | 2020-06-22 23:21:21 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,933 bytes |
| コンパイル時間 | 939 ms |
| コンパイル使用メモリ | 115,196 KB |
| 実行使用メモリ | 29,532 KB |
| 最終ジャッジ日時 | 2024-07-03 18:58:30 |
| 合計ジャッジ時間 | 3,390 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 RE * 10 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Linq;
namespace Problem1073
{
class Program
{
static void Main(string[] args)
{
const long mod = 7 + (long)1e9;
long N = GetLong();
var table = new long[N + 1];
for(int i = 0; i <= N; i++)
{
switch(i)
{
case 0:
table[i] = 1;
break;
case 1:
table[i] = ModInv(6, mod);
break;
case 2:
table[i] = (table[0] + table[1]) % mod * table[1] % mod;
break;
case 3:
table[i] = ((table[0] + table[1]) %mod + table[2]) % mod * table[1] % mod;
break;
case 4:
table[i] = (((table[0] + table[1]) % mod + table[2]) % mod + table[3]) % mod * table[1] % mod;
break;
case 5:
table[i] = ((((table[0] + table[1]) % mod + table[2]) % mod + table[3]) % mod + table[4]) % mod * table[1] % mod;
break;
case 6:
table[i] = (((((table[0] + table[1]) % mod + table[2]) % mod + table[3]) % mod + table[4]) % mod + table[5]) % mod * table[1] % mod;
break;
default:
table[i] = (((((table[i - 6] + table[i - 5]) % mod + table[i - 4]) % mod + table[i - 3]) % mod + table[i - 2]) % mod + table[i - 1]) % mod * table[1] % mod;
break;
}
}
Console.WriteLine(table[N]);
}
public static long ModInv(long n, long mod)
{
long b = mod;
long u = 1;
long v = 0;
while (b != 0)
{
long t = n / b;
n -= t * b;
Swap(ref n, ref b);
u -= t * v;
Swap(ref u, ref v);
}
u %= mod;
if(u < 0)
{
u += mod;
}
return u;
}
static void Swap(ref long a, ref long b)
{
long temp = a;
a = b;
b = temp;
}
public static int GetInt() => int.Parse(Console.ReadLine());
public static int[] GetIntArray() => Console.ReadLine().Split().Select(int.Parse).ToArray();
public static double GetDouble() => double.Parse(Console.ReadLine());
public static double[] GetDoubleArray() => Console.ReadLine().Split().Select(double.Parse).ToArray();
public static long GetLong() => long.Parse(Console.ReadLine());
public static long[] GetLongArray() => Console.ReadLine().Split().Select(long.Parse).ToArray();
}
}
Yusei Kato