結果
| 問題 |
No.2585 How many "Who is Santa?"
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-12-17 19:44:16 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
AC
|
| 実行時間 | 54 ms / 1,225 ms |
| コード長 | 1,241 bytes |
| コンパイル時間 | 10,188 ms |
| コンパイル使用メモリ | 169,400 KB |
| 実行使用メモリ | 183,664 KB |
| 最終ジャッジ日時 | 2024-09-27 08:03:00 |
| 合計ジャッジ時間 | 12,507 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (105 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
static int NN => int.Parse(ReadLine());
static int[] NMi => ReadLine().Split().Select(c => int.Parse(c) - 1).ToArray();
static int[][] NMap(int n) => Enumerable.Repeat(0, n).Select(_ => NMi).ToArray();
public static void Main()
{
Solve();
}
static void Solve()
{
var mod = 998_244_353;
var n = NN;
if (n == 2)
{
WriteLine(0);
return;
}
var ans = (long)n * (n - 1) % mod;
var mul = (Exp(n - 2, n - 1, mod) + (n - 2) * ((Exp(n - 1, n - 2, mod) - Exp(n - 2, n - 2, mod) + mod) % mod) % mod
+ (Exp(n - 1, n - 2, mod) - Exp(n - 3, n - 2, mod) + mod) % mod) % mod;
WriteLine(ans * mul % mod);
}
static long Exp(long n, long p, int mod)
{
long _n = n % mod;
var _p = p;
var result = 1L;
if ((_p & 1) == 1) result *= _n;
while (_p > 0)
{
_n = _n * _n % mod;
_p >>= 1;
if ((_p & 1) == 1) result = result * _n % mod;
}
return result;
}
}