結果
問題 |
No.1470 Mex Sum
|
ユーザー |
![]() |
提出日時 | 2021-04-09 21:24:52 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 48 ms / 2,000 ms |
コード長 | 667 bytes |
コンパイル時間 | 2,045 ms |
コンパイル使用メモリ | 194,956 KB |
最終ジャッジ日時 | 2025-01-20 13:28:49 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 49 |
ソースコード
#include <bits/stdc++.h> using namespace std; int n; vector<long long> cnt(4, 0); long long solve(); int main() { cin >> n; for (int i = 0; i < n; ++i) { int a; cin >> a; if (a <= 2) ++cnt[a]; else ++cnt[3]; } cout << solve() << endl; return 0; } long long solve() { long long res = 0; auto mex = [](int l, int r) { if (l > r) swap(l, r); if (l != 1) return 1; if (r == 2) return 3; return 2; }; for (int i = 1; i <= 3; ++i) for (int j = i; j <= 3; ++j) { long long now = cnt[i] * cnt[j]; if (i == j) now = cnt[i] * (cnt[i] - 1) / 2; res += now * mex(i, j); } return res; }