結果
問題 | No.1193 Penguin Sequence |
ユーザー | cn_449 |
提出日時 | 2020-08-22 14:47:06 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,265 bytes |
コンパイル時間 | 1,703 ms |
コンパイル使用メモリ | 148,412 KB |
実行使用メモリ | 34,100 KB |
最終ジャッジ日時 | 2024-10-15 09:06:01 |
合計ジャッジ時間 | 12,592 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 198 ms
27,504 KB |
testcase_12 | AC | 202 ms
27,592 KB |
testcase_13 | AC | 311 ms
32,384 KB |
testcase_14 | AC | 282 ms
31,728 KB |
testcase_15 | AC | 342 ms
33,348 KB |
testcase_16 | AC | 156 ms
24,592 KB |
testcase_17 | AC | 27 ms
19,672 KB |
testcase_18 | AC | 44 ms
20,992 KB |
testcase_19 | WA | - |
testcase_20 | AC | 271 ms
31,552 KB |
testcase_21 | AC | 212 ms
28,132 KB |
testcase_22 | AC | 50 ms
21,504 KB |
testcase_23 | AC | 178 ms
26,956 KB |
testcase_24 | AC | 157 ms
26,404 KB |
testcase_25 | AC | 80 ms
22,744 KB |
testcase_26 | AC | 37 ms
20,384 KB |
testcase_27 | AC | 297 ms
32,232 KB |
testcase_28 | AC | 196 ms
27,604 KB |
testcase_29 | AC | 303 ms
32,324 KB |
testcase_30 | AC | 107 ms
23,780 KB |
testcase_31 | AC | 89 ms
23,248 KB |
testcase_32 | AC | 237 ms
30,564 KB |
testcase_33 | AC | 159 ms
26,584 KB |
testcase_34 | AC | 130 ms
25,576 KB |
testcase_35 | AC | 163 ms
26,664 KB |
testcase_36 | AC | 128 ms
25,420 KB |
testcase_37 | AC | 297 ms
32,016 KB |
testcase_38 | AC | 29 ms
19,464 KB |
testcase_39 | AC | 28 ms
19,668 KB |
testcase_40 | AC | 27 ms
19,712 KB |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <string> #include <queue> #include <stack> #include <set> #include <map> #include <iomanip> #include <utility> #include <tuple> #include <functional> #include <bitset> #include <cassert> #include <complex> #include <stdio.h> #include <time.h> #include <numeric> #include <random> #include <unordered_map> #include <unordered_set> #define all(a) a.begin(),a.end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define pb push_back #define debug(x) cerr << __LINE__ << ' ' << #x << ':' << x << '\n' #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> P; typedef complex<ld> com; constexpr int inf = 1000000010; constexpr ll INF = 1000000000000000010; constexpr ld eps = 1e-12; constexpr ld pi = 3.141592653589793238; template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; } constexpr ll mod = 998244353; vector<ll> fac, inv, facinv; void modcalc(int n) { fac.resize(n); inv.resize(n); facinv.resize(n); fac[0] = 1; fac[1] = 1; inv[1] = 1; facinv[0] = 1; facinv[1] = 1; for (ll i = 2; i < n; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; facinv[i] = facinv[i - 1] * inv[i] % mod; } } ll modinv(ll a) { a %= mod; if (a == 0) abort(); if (a < (ll)inv.size()) return inv[a]; ll b = mod, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= mod; if (u < 0) u += mod; return u; } ll modpow(ll a, ll b, ll m = mod) { ll ans = 1; a %= m; while (b) { if (b & 1) ans = ans * a % m; a = a * a % m; b >>= 1; } return ans; } ll modcomb(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; return fac[n] * facinv[k] % mod * facinv[n - k] % mod; } ll modperm(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; return fac[n] * facinv[n - k] % mod; } ll modhom(ll n, ll k) { if (n < 0 || k < 0 || n == 0 && k > 0) return 0; if (n == 0 && k == 0) return 1; return fac[n + k - 1] * facinv[k] % mod * facinv[n - 1] % mod; } template<class T> class segtree { int n; vector<T> data; T id = 0; T operation(T a, T b) { return (a + b) % mod; }; public: segtree(int _n) { n = 1; while (n < _n + 2) n <<= 1; data = vector<T>(2 * n, id); } void change(int i, T x) { i += n; data[i] = x; while (i > 1) { i >>= 1; data[i] = operation(data[i << 1], data[i << 1 | 1]); } } void add(int i, T x) { change(i, data[i + n] + x); } T get(int a, int b) { T left = id; T right = id; a += n; b += n; while (a < b) { if (a & 1) left = operation(left, data[a++]); if (b & 1) right = operation(data[--b], right); a >>= 1; b >>= 1; } return operation(left, right); } T get_all() { return data[1]; } T operator[](int i) { return data[i + n]; } }; vector<int> shrink(vector<int> vec) { int vecsize = vec.size(); vector<int> tmpvec = vec; sort(tmpvec.begin(), tmpvec.end()); tmpvec.erase(unique(tmpvec.begin(), tmpvec.end()), tmpvec.end()); vector<int> res(vecsize); for (int i = 0; i < vecsize; i++) res[i] = lower_bound(tmpvec.begin(), tmpvec.end(), vec[i]) - tmpvec.begin(); return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); modcalc(700010); ll n; cin >> n; vector<int> a(n); map<int, int> mp; rep(i, n) { cin >> a[i]; mp[a[i]]++; } a = shrink(a); segtree<ll> s(n); ll inv = 0; rep(i, n) { inv += s.get(a[i] + 1, n + 1); s.add(a[i], 1); } ll ans = 0; ll sum = n * (n - 1) / 2; for (auto i : mp) { ll v = i.second; sum -= v * (v - 1) / 2; } sum %= mod; sum *= modinv(n); sum %= mod; for (ll i = 1; i <= n; i++) { ll pre = i * (i - 1) / 2; pre %= mod; pre *= i; pre %= mod; pre *= modinv(n); pre %= mod; pre *= sum; pre %= mod; ans += pre; ans += inv * modcomb(n - 2, i - 2) % mod * modinv(modcomb(n, i)) % mod; ans %= mod; } for (int i = 1; i <= n; i++) { ans *= modcomb(n, i); ans %= mod; } cout << ans << '\n'; }