結果
問題 | No.1470 Mex Sum |
ユーザー |
|
提出日時 | 2021-04-12 11:12:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 17 ms / 2,000 ms |
コード長 | 536 bytes |
コンパイル時間 | 1,649 ms |
コンパイル使用メモリ | 168,292 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 09:10:55 |
合計ジャッジ時間 | 3,839 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 49 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); long long cnt1 = 0, cnt2 = 0; for (int i = 0; i < n; i++) { cin >> a[i]; cnt1 += (a[i] == 1); cnt2 += (a[i] == 2); } long long cnt3 = n - cnt1 - cnt2; long long ans = 0; ans += cnt1 * cnt2 * 3; ans += cnt1 * cnt3 * 2 + cnt1 * (cnt1 - 1) / 2 * 2; ans += cnt2 * (cnt2 - 1) / 2 + cnt2 * cnt3 + cnt3 * (cnt3 - 1) / 2; cout << ans << endl; }