結果
| 問題 |
No.1310 量子アニーリング
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-12-14 11:00:25 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 197 ms / 2,000 ms |
| コード長 | 1,089 bytes |
| コンパイル時間 | 2,049 ms |
| コンパイル使用メモリ | 113,076 KB |
| 実行使用メモリ | 26,500 KB |
| 最終ジャッジ日時 | 2024-09-20 00:38:14 |
| 合計ジャッジ時間 | 4,199 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
class G
{
static void Main()
{
var n = int.Parse(Console.ReadLine());
var ncr = new MInt[n + 1];
ncr[0] = 1;
for (int i = 0; i < n; i++)
ncr[i + 1] = ncr[i] * (n - i) / (i + 1);
MInt r = 0;
for (int d = 0; d <= n; d += 2)
r += 2 * ncr[d] * MInt.MPow(2, Math.Abs(2 * d - n));
Console.WriteLine(r);
}
}
struct MInt
{
const long M = 998244353;
public long V;
public MInt(long v) { V = (v %= M) < 0 ? v + M : v; }
public override string ToString() => $"{V}";
public static implicit operator MInt(long v) => new MInt(v);
public static MInt operator -(MInt x) => -x.V;
public static MInt operator +(MInt x, MInt y) => x.V + y.V;
public static MInt operator -(MInt x, MInt y) => x.V - y.V;
public static MInt operator *(MInt x, MInt y) => x.V * y.V;
public static MInt operator /(MInt x, MInt y) => x.V * y.Inv().V;
public static long MPow(long b, long i)
{
long r = 1;
for (; i != 0; b = b * b % M, i >>= 1) if ((i & 1) != 0) r = r * b % M;
return r;
}
public MInt Pow(long i) => MPow(V, i);
public MInt Inv() => MPow(V, M - 2);
}