結果
問題 | No.1193 Penguin Sequence |
ユーザー | ianCK |
提出日時 | 2020-09-25 20:19:09 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,282 bytes |
コンパイル時間 | 698 ms |
コンパイル使用メモリ | 49,024 KB |
実行使用メモリ | 10,908 KB |
最終ジャッジ日時 | 2024-06-28 05:58:43 |
合計ジャッジ時間 | 4,500 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 46 ms
9,240 KB |
testcase_17 | AC | 1 ms
5,376 KB |
testcase_18 | AC | 12 ms
7,296 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 14 ms
7,424 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 22 ms
7,936 KB |
testcase_26 | AC | 10 ms
7,168 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | AC | 6 ms
7,040 KB |
testcase_39 | AC | 6 ms
7,040 KB |
testcase_40 | AC | 7 ms
7,040 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:63:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 63 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:68:43: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 68 | for (int i = 1; i <= n; i++) scanf("%d", &a[i]); | ~~~~~^~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <vector> #include <string.h> #include <algorithm> using namespace std; #define PB push_back typedef long long int ll; constexpr int kN = int(2E5 + 10), kMod = 998244353; struct BIT { int val[kN]; void init() {memset(val, 0, sizeof(val));} void add(int pos) { while (pos < kN) { val[pos]++; pos += pos & -pos; } return ; } int ask(int pos) { int ans = 0; while (pos) { ans += val[pos]; pos ^= pos & -pos; } return ans; } }; ll Pow(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) ans = ans * a % kMod; a = a * a % kMod; b >>= 1; } return ans; } ll Rev(ll n) {return Pow(n, kMod - 2);} ll f[kN], inf[kN]; void pre() { f[0] = f[1] = inf[0] = inf[1] = 1; for (int i = 2; i < kN; i++) f[i] = f[i - 1] * i % kMod; inf[kN - 1] = Rev(f[kN - 1]); for (int i = kN - 1; i > 2; i--) inf[i - 1] = inf[i] * i % kMod; return ; } ll C(int n, int m) {return f[n] * inf[m] % kMod * inf[n - m] % kMod;} int a[kN], rnk[kN]; ll same[kN]; BIT bit; int main() { int n; ll ans = 0, tot = 1, tmp = 0, cnt = 0, ccnt = 0; vector<int> v; scanf("%d", &n); if (n == 1) { printf("0\n"); return 0; } for (int i = 1; i <= n; i++) scanf("%d", &a[i]); pre(); for (int i = 1; i <= n; i++) tot = tot * C(n, i) % kMod; // inside bit.init(); for (int i = 1; i <= n; i++) v.PB(a[i]); sort(v.begin(), v.end()); v.resize(unique(v.begin(), v.end()) - v.begin()); for (int i = 1; i <= n; i++) rnk[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1; for (int i = 1; i <= n; i++) { cnt += (i - 1) - bit.ask(rnk[i]); bit.add(rnk[i]); } for (int i = 2; i <= n; i++) tmp += ll(i) * (i - 1) % kMod; tmp %= kMod; ans = tmp * tot % kMod * Rev(n) % kMod * Rev(n - 1) % kMod * cnt % kMod; // between for (int i = 1; i <= n; i++) same[rnk[i]]++; for (int i = 1; i <= n; i++) if (same[rnk[i]]) { ccnt += (n - same[rnk[i]]) * same[rnk[i]] % kMod; same[rnk[i]] = 0; } ccnt %= kMod; ccnt = ccnt * Rev(2) % kMod; tmp = ll(n) * (n + 1) % kMod * Rev(2) % kMod; tmp = tmp * tmp % kMod; for (int i = 1; i <= n; i++) tmp -= i * i % kMod; tmp %= kMod; if (tmp < 0) tmp += kMod; tmp = tmp * Rev(2) % kMod; ans += tmp * tot % kMod * ccnt % kMod * Rev(n) % kMod * Rev(n) % kMod; printf("%lld\n", ans % kMod); }