提出 #62535845


ソースコード 拡げる

/*
Author : Mikira
Sat 08 Feb 2025 08:17:59 PM HKT
*/

#include "bits/stdc++.h"
using namespace std;

typedef long long LL;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> PII;
typedef pair<int, int> pii;
typedef pair<LL, LL> PLL;
typedef pair<LL, LL> pll;
typedef long double ld;

#define rep(i, a, b) for(int i = a; i < int(b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define popf pop_front
#define pf push_front
#define popb pop_back
#define pb push_back
#define fi first
#define se second

const double EPS = 1e-9;
const int INFMEM = 63;

// Do dir^1 to get reverse direction
const int dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
const int dy[8] = {1, -1, 0, 0, 1, -1, -1, 1};
const char dch[4] = {'R', 'L', 'D', 'U'};

// Do (dir + 2)%4 to get reverse direction
// const int dx[8] = {-1,0,1,0,-1,1,1,-1};
// const int dy[8] = {0,1,0,-1,1,1,-1,-1};
// const char dch[4] = {'U','R','D','L'};
const double PI = 3.141592653589793;

inline void fasterios() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);
}
#define endl '\n'
const int MOD = 1000000007;
// const int MOD = 998244353;
typedef __int128 BigNum;
BigNum labs(BigNum a) {
  return a < 0 ? -a : a;
}
struct Fraction {
  BigNum a, b;
  Fraction(BigNum _a = 0, BigNum _b = 1) {
    a = _a;
    b = _b;
    assert(b);
    LL curgcd = __gcd(labs(a), labs(b));
    a /= curgcd;
    b /= curgcd;
    if (b < 0) a = -a, b = -b;
  }
  bool operator ==(const Fraction &other) const {
    return a == other.a && b == other.b;
  }
  bool operator <(const Fraction &other) const {
    return a * other.b < b * other.a;
  }
  Fraction operator +(const Fraction &other) const {
    return Fraction(a * other.b + b * other.a, other.b * b);
  }
  Fraction operator -() const {
    return Fraction(-a, b);
  }
  Fraction operator -(const Fraction &other) const {
    return Fraction(a * other.b - b * other.a, other.b * b);
  }
  Fraction operator *(const Fraction &other) const {
    return Fraction(a * other.a, other.b * b);
  }
  Fraction operator /(const Fraction &other) const {
    return Fraction(a * other.b, b * other.a);
  }
  Fraction max(const Fraction &other) const {
    if (*this < other) return other;
    return *this;
  }
  Fraction min(const Fraction &other) const {
    if (*this < other) return *this;
    return other;
  }
  double val() {
    assert(b);
    return (double)a / b;
  }
  friend istream& operator>>(istream& is, Fraction &p) {
    LL tmp;
    is >> tmp;
    p = Fraction(tmp);
    return is;
  }
  friend ostream& operator<<(ostream& os, Fraction p) {
    return os << "(" << (LL)p.a << "/" << (LL)p.b << ")";
  }
};
// Don't forget to read all the inputs before returning!!!
const int kMaxFace = 1e5;
int solve() {
  int n; cin >> n;
  vector <map<LL, LL>> faces(n);
  vector <LL> diceSize(n);
  vector <int> perm(n);
  iota(all(perm), 0);
  for (int i = 0; i < n; i++) {
    int k; cin >> k;
    diceSize[i] = k;
    rep(j, 0, k) {
      int cur; cin >> cur;
      faces[i][cur]++;
    }
  }
  sort(all(perm), [&](const int &a, const int &b) {
    return faces[a].size() < faces[b].size();
  });
  Fraction ans = 0;
  rep(ii, 0, n) {
    int i = perm[ii];
    rep(jj, ii + 1, n) {
      int j = perm[jj];
      Fraction currentAns = 0;
      trav(cur, faces[i]) {
        if (!faces[j].count(cur.fi)) continue;
        currentAns = currentAns + Fraction(faces[j][cur.fi], diceSize[j]) * Fraction(cur.se, diceSize[i]);
      }
      ans = max(currentAns, ans);
    }
  }
  cout << fixed << setprecision(15) << ans.val() << endl;
  return 0;
}

int main() {
  fasterios();
  solve();
}

提出情報

提出日時
問題 D - Doubles
ユーザ hocky
言語 C++ 20 (gcc 12.2)
得点 400
コード長 3858 Byte
結果 AC
実行時間 1097 ms
メモリ 10092 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 2
AC × 26
セット名 テストケース
Sample sample_01.txt, sample_02.txt
All 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, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, sample_01.txt, sample_02.txt
ケース名 結果 実行時間 メモリ
random_01.txt AC 7 ms 3844 KiB
random_02.txt AC 7 ms 3816 KiB
random_03.txt AC 54 ms 9144 KiB
random_04.txt AC 71 ms 9716 KiB
random_05.txt AC 7 ms 3844 KiB
random_06.txt AC 7 ms 3700 KiB
random_07.txt AC 56 ms 9452 KiB
random_08.txt AC 67 ms 9624 KiB
random_09.txt AC 7 ms 3780 KiB
random_10.txt AC 7 ms 3684 KiB
random_11.txt AC 49 ms 9092 KiB
random_12.txt AC 61 ms 9492 KiB
random_13.txt AC 5 ms 3752 KiB
random_14.txt AC 38 ms 8728 KiB
random_15.txt AC 5 ms 3692 KiB
random_16.txt AC 30 ms 7688 KiB
random_17.txt AC 1 ms 3908 KiB
random_18.txt AC 5 ms 3808 KiB
random_19.txt AC 367 ms 10032 KiB
random_20.txt AC 93 ms 10052 KiB
random_21.txt AC 25 ms 10012 KiB
random_22.txt AC 6 ms 3804 KiB
random_23.txt AC 1094 ms 10092 KiB
random_24.txt AC 1097 ms 10008 KiB
sample_01.txt AC 1 ms 3616 KiB
sample_02.txt AC 1 ms 3784 KiB