結果
問題 | No.2742 Car Flow |
ユーザー |
![]() |
提出日時 | 2024-04-21 07:04:08 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 15 ms / 2,000 ms |
コード長 | 811 bytes |
コンパイル時間 | 1,083 ms |
コンパイル使用メモリ | 78,080 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-13 05:48:43 |
合計ジャッジ時間 | 3,001 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 50 |
ソースコード
#include <concepts> #include <iostream> using namespace std; template <std::integral T, std::signed_integral U> constexpr T extended_euclidean(const T &n, const T &m, U &x, U &y) noexcept { if (m == 0) { x = 1, y = 0; return n; } T t = n / m, g = extended_euclidean(m, n - m * t, y, x); y -= x * t; return g; } template <std::integral T, T m> constexpr T inv(T n) noexcept { std::make_signed_t<T> x, y; extended_euclidean(n, m, x, y); return x; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); using ll = long long; ll n, cnt = 0; cin >> n; for (int a, i = 0; i < n; ++i) cin >> a, cnt += a; constexpr ll M = 998'244'353; cout << (min(cnt, n - cnt) * inv<ll, M>(n) % M + M) % M << '\n'; return 0; }