結果
問題 | No.1470 Mex Sum |
ユーザー |
|
提出日時 | 2021-04-09 22:18:57 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 806 bytes |
コンパイル時間 | 2,049 ms |
コンパイル使用メモリ | 193,996 KB |
最終ジャッジ日時 | 2025-01-20 14:38:32 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 14 WA * 35 |
ソースコード
#define _USE_MATH_DEFINES#include <bits/stdc++.h>using namespace std;signed main() {ios::sync_with_stdio(false); cin.tie(0);int n;cin >> n;vector<int> a(n);for (auto& x : a) cin >> x;vector<int> cnt1(n + 1), cnt2(n + 1);for (int i = 0; i < n; i++) {cnt1[i + 1] = cnt1[i] + (a[i] == 1);cnt2[i + 1] = cnt2[i] + (a[i] == 2);}long long ans = 0;for (int i = 0; i < n; i++) {if (a[i] == 1) {ans += 2 * cnt1[i];ans += 3 * cnt2[i];ans += 2 * (i - cnt1[i] - cnt2[i]);} else if (a[i] == 2) {ans += 3 * cnt1[i];ans += 1 * cnt2[i];ans += 1 * (i - cnt1[i] - cnt2[i]);} else {ans += 2 * cnt1[i];ans += 1 * cnt1[i];ans += 1 * (i - cnt1[i] - cnt2[i]);}}cout << ans << endl;return 0;}