結果
| 問題 |
No.1470 Mex Sum
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-04-09 21:32:36 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 54 ms / 2,000 ms |
| コード長 | 1,159 bytes |
| コンパイル時間 | 2,921 ms |
| コンパイル使用メモリ | 194,388 KB |
| 最終ジャッジ日時 | 2025-01-20 13:40:37 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 49 |
ソースコード
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i))
#define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;
int mex(int a, int b) {
if (a != 1 and b != 1) return 1;
if (a != 2 and b != 2) return 2;
if (a != 3 and b != 3) return 3;
if (a != 4 and b != 4) return 4;
assert (false);
}
int64_t solve(int n, vector<int64_t> a) {
int64_t ans = 0;
array<int, 4> k = {};
REP (i, n) {
int b = min<int64_t>(3, a[i]);
REP3 (c, 1, 4) {
ans += k[c] * mex(b, c);
}
k[b] += 1;
}
return ans;
}
// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
constexpr char endl = '\n';
int N;
cin >> N;
vector<int64_t> A(N);
REP (i, N) { cin >> A[i]; }
auto ans = solve(N, A);
cout << ans << endl;
return 0;
}