提出 #70420733


ソースコード 拡げる

#define LOCAL
#include <bits/stdc++.h>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const multiset<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

template <class T> auto vect(const T& v, int n) { return vector<T>(n, v); }
template <class T, class... D> auto vect(const T& v, int n, D... m) {
  return vector<decltype(vect(v, m...))>(n, vect(v, m...));
}

using int64 = long long;
using int128 = __int128_t;
using ii = pair<int, int>;
#define SZ(x) (int)((x).size())
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
mt19937_64 mrand(random_device{}());
int64 rnd(int64 x) { return mrand() % x; }
constexpr inline int lg2(int64 x) { return x == 0 ? -1 : sizeof(int64) * 8 - 1 - __builtin_clzll(x); }
constexpr inline int64 p2ceil(int64 x) { return 1LL << (lg2(x - 1) + 1); }
template <class T> void out(const vector<T>& a) { for (int i = 0; i < SZ(a); ++i) cout << a[i] << " \n"[i + 1 == SZ(a)]; }
template <class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template <class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template <class T> void dedup(vector<T>& v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); }
inline void add_mod(int& x, int y) { x += y; if (x >= MOD) x -= MOD; }
inline void sub_mod(int& x, int y) { x += MOD - y; if (x >= MOD) x -= MOD; }
inline int mod(int x) { return x >= MOD ? x - MOD : x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n;
  cin >> n;
  map<int, int> cnt;
  int64 ret = 1LL * n * (n - 1) * (n - 2) / 6;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    cnt[x]++;
  }
  for (auto& [k, v] : cnt) {
    ret -= 1LL * v * (v - 1) * (v - 2) / 6;
  }
  vector<int64> dp(4);
  dp[0] = 1;
  for (auto& [k, v] : cnt) {
    auto ndp = dp;
    for (int k = 0; k < 3; ++k) {
      ndp[k + 1] += dp[k] * v;
    }
    swap(dp, ndp);
  }
  ret -= dp[3];
  cout << ret << '\n';
  return 0;
}

提出情報

提出日時
問題 C - Odd One Subsequence
ユーザ cuiaoxiang
言語 C++ 20 (gcc 12.2)
得点 300
コード長 3885 Byte
結果 AC
実行時間 86 ms
メモリ 12776 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 2
AC × 28
セット名 テストケース
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 1 ms 3520 KiB
example_01.txt AC 1 ms 3480 KiB
hand_00.txt AC 86 ms 12776 KiB
hand_01.txt AC 9 ms 3420 KiB
hand_02.txt AC 17 ms 3504 KiB
hand_03.txt AC 1 ms 3392 KiB
hand_04.txt AC 1 ms 3320 KiB
hand_05.txt AC 9 ms 3424 KiB
random_00.txt AC 68 ms 9384 KiB
random_01.txt AC 70 ms 9336 KiB
random_02.txt AC 71 ms 9356 KiB
random_03.txt AC 70 ms 9464 KiB
random_04.txt AC 74 ms 9552 KiB
random_05.txt AC 34 ms 4376 KiB
random_06.txt AC 33 ms 4416 KiB
random_07.txt AC 32 ms 4468 KiB
random_08.txt AC 33 ms 4464 KiB
random_09.txt AC 33 ms 4364 KiB
random_10.txt AC 17 ms 3420 KiB
random_11.txt AC 17 ms 3632 KiB
random_12.txt AC 16 ms 3448 KiB
random_13.txt AC 17 ms 3436 KiB
random_14.txt AC 17 ms 3448 KiB
random_15.txt AC 10 ms 3460 KiB
random_16.txt AC 10 ms 3488 KiB
random_17.txt AC 10 ms 3476 KiB
random_18.txt AC 9 ms 3428 KiB
random_19.txt AC 9 ms 3404 KiB