結果

問題 No.1470 Mex Sum
コンテスト
ユーザー a01sa01to
提出日時 2025-11-10 00:21:16
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 715 bytes
コンパイル時間 2,931 ms
コンパイル使用メモリ 278,420 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-11-10 00:21:22
合計ジャッジ時間 5,864 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> cnt(3, 0);
  ll ans = 0;
  rep(i, n) {
    if (a[i] == 1) {
      ans += 2 * cnt[0];
      ans += 3 * cnt[1];
      ans += 2 * cnt[2];
      cnt[0]++;
    }
    else if (a[i] == 2) {
      ans += 3 * cnt[0];
      ans += 1 * cnt[1];
      ans += 1 * cnt[2];
      cnt[1]++;
    }
    else {
      ans += 2 * cnt[0];
      ans += 1 * cnt[1];
      ans += 1 * cnt[2];
      cnt[2]++;
    }
  }
  cout << ans << '\n';
  return 0;
}
0