結果
| 問題 |
No.2585 How many "Who is Santa?"
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2023-12-16 01:35:04 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,410 bytes |
| コンパイル時間 | 438 ms |
| コンパイル使用メモリ | 42,056 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-27 06:48:29 |
| 合計ジャッジ時間 | 1,449 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 WA * 1 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 2585.cc: No.2585 How many "Who is Santa?" - yukicoder
*/
#include<cstdio>
#include<algorithm>
using namespace std;
/* constant */
const int MOD = 998244353;
/* typedef */
template<const int MOD>
struct MI {
int v;
MI(): v() {}
MI(int _v): v(_v % MOD) {}
MI(long long _v): v(_v % MOD) {}
MI operator+(const MI m) const { return MI(v + m.v); }
MI operator-(const MI m) const { return MI(v + MOD - m.v); }
MI operator*(const MI m) const { return MI((long long)v * m.v); }
MI &operator+=(const MI m) { return (*this = *this + m); }
MI &operator-=(const MI m) { return (*this = *this - m); }
MI &operator*=(const MI m) { return (*this = *this * m); }
bool operator==(const MI m) const { return v == m.v; }
bool operator!=(const MI m) const { return v != m.v; }
MI pow(int n) const { // a^n % MOD
MI pm = 1, a = *this;
while (n > 0) {
if (n & 1) pm *= a;
a *= a;
n >>= 1;
}
return pm;
}
MI inv() const { return pow(MOD - 2); }
MI operator/(const MI m) const { return *this * m.inv(); }
MI &operator/=(const MI m) { return (*this = *this / m); }
};
typedef MI<MOD> mi;
/* global variables */
/* subroutines */
/* main */
int main() {
int n;
scanf("%d", &n);
auto v = mi(n - 1).pow(n) * n;
if (n >= 3) v -= mi(n - 1) * mi(n - 3).pow(n - 2) * n;
printf("%d\n", v.v);
return 0;
}
tnakao0123