Submission #14869536


Source Code Expand

Copy
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cstdio>
#include <bitset>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <functional>
#include <stack>
#include <cmath>
#include <string>

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

constexpr int MOD = 1000000007;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

inline int popcount(ll x) { return __builtin_popcountll(x); }
inline int div2num(ll x) { return __builtin_ctzll(x); }
inline bool bit(ll x, int b) { return (x >> b) & 1; }

template <class T>
string to_string(T s);
template <class S, class T>
string to_string(pair<S, T> p);
string to_string(string s) { return s; }
string to_string(const char s[]) { return to_string(string(s)); }

template <class T>
string to_string(T v) {
  if (v.empty()) return "{}";
  string ret = "{";
  for (auto x : v) ret += to_string(x) + ",";
  ret.back() = '}';
  return ret;
}

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + ":" + to_string(p.second) + "}";
}
void debug() { cerr << endl; }

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

struct IO {
#ifdef _WIN32
  inline char getchar_unlocked() { return getchar(); }
  inline void putchar_unlocked(char c) { putchar(c); }
#endif
  std::string separator = " ";
  template <class T>
  inline void read(T &x) {
    char c;
    do {
      c = getchar_unlocked();
    } while (c != '-' && (c < '0' || '9' < c));
    bool minus = 0;
    if (c == '-') {
      minus = 1;
      c = getchar_unlocked();
    }
    x = 0;
    while ('0' <= c && c <= '9') {
      x *= 10;
      x += c - '0';
      c = getchar_unlocked();
    }
    if (minus) x = -x;
  }
  inline void read(std::string &x) {
    char c;
    do {
      c = getchar_unlocked();
    } while (c == ' ' || c == '\n');
    x.clear();
    do {
      x += c;
      c = getchar_unlocked();
    } while (c != ' ' && c != '\n' && c != EOF);
  }
  template <class T>
  inline void read(std::vector<T> &v) {
    for (auto &x : v) read(x);
  }
  template <class S, class T>
  inline void read(std::pair<S, T> &p) {
    read(p.first);
    read(p.second);
  }
  template <class Head, class... Tail>
  inline void read(Head &head, Tail &... tail) {
    read(head);
    read(tail...);
  }
  template <class T>
  inline void write(T x) {
    char buf[32];
    int p = 0;
    if (x < 0) {
      x = -x;
      putchar_unlocked('-');
    }
    if (x == 0) putchar_unlocked('0');
    while (x > 0) {
      buf[p++] = (x % 10) + '0';
      x /= 10;
    }
    while (p) {
      putchar_unlocked(buf[--p]);
    }
  }
  inline void write(std::string x) {
    for (char c : x) putchar_unlocked(c);
  }
  inline void write(const char s[]) {
    for (int i = 0; s[i] != 0; ++i) putchar_unlocked(s[i]);
  }
  template <class T>
  inline void write(std::vector<T> v) {
    if (v.empty()) return;
    for (auto itr = v.begin(); itr + 1 != v.end(); ++itr) {
      write(*itr);
      write(separator);
    }
    write(v.back());
  }
  template <class Head, class... Tail>
  inline void write(Head head, Tail... tail) {
    write(head);
    write(separator);
    write(tail...);
  }
  template <class Head, class... Tail>
  inline void writeln(Head head, Tail... tail) {
    write(head, tail...);
    write("\n");
  }
  void set_separator(std::string s) { separator = s; }
} io;

struct Prime {
  int n;
  vector<int> table;
  vector<int> primes;
  Prime(int _n = 100000) {
    n = _n + 1;
    table.resize(n, -1);
    table[0] = 0;
    table[1] = -1;
    for (int i = 2; i * i < n; ++i) {
      if (table[i] == -1) {
        for (int j = i * i; j < n; j += i) {
          table[j] = i;
        }
      }
    }
  }
  void enumerate_primes() {
    primes.clear();
    for (int i = 2; i < n; ++i) {
      if (table[i] == -1) primes.push_back(i);
    }
  }
  vector<pair<long long, int>> prime_factor(long long x) {
    map<long long, int> mp;
    long long div = 2;
    int p = 0;
    while (n <= x && div * div <= x) {
      if (x % div == 0) {
        mp[div]++;
        x /= div;
      } else {
        if (p + 1 < primes.size()) {
          div = primes[++p];
        } else {
          div++;
        }
      }
    }
    if (x < n) {
      while (table[x] != -1) {
        mp[table[x]]++;
        x /= table[x];
      }
    }
    if (x > 1) mp[x]++;
    vector<pair<long long, int>> ret;
    for (auto p : mp) ret.push_back(p);
    return ret;
  }
};

template <int MOD = 1000000007>
struct Math {
  vector<long long> fact, factinv, inv;
  Math(int n = 100000) {
    fact.resize(n + 1);
    factinv.resize(n + 1);
    inv.resize(n + 1);
    fact[0] = fact[1] = 1;
    factinv[0] = factinv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i <= n; ++i) {
      fact[i] = fact[i - 1] * i % MOD;
      inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
      factinv[i] = factinv[i - 1] * inv[i] % MOD;
    }
  }
  long long C(int n, int r) {
    if (n < r || n < 0 || r < 0) {
      return 0;
    } else {
      return fact[n] * (factinv[r] * factinv[n - r] % MOD) % MOD;
    }
  }
  long long P(int n, int r) {
    if (n < r || n < 0 || r < 0) {
      return 0;
    } else {
      return fact[n] * factinv[n - r] % MOD;
    }
  }
  long long H(int n, int r) { return C(n + r - 1, r); }
};

struct UnionFind {
  vector<int> data;
  vector<vector<int>> groups;
  UnionFind(int n) : data(n, -1) {}
  int root(int v) { return data[v] < 0 ? v : data[v] = root(data[v]); }
  bool unite(int u, int v) {
    if ((u = root(u)) == (v = root(v))) {
      return 1;
    } else {
      if (-data[u] < -data[v]) swap(u, v);
      data[u] += data[v];
      data[v] = u;
      return 0;
    }
  }
  int size(int v) { return -data[root(v)]; }
  void make_groups() {
    map<int, vector<int>> mp;
    for (int i = 0; i < data.size(); ++i) mp[root(i)].push_back(i);
    groups.clear();
    for (auto p : mp) groups.push_back(p.second);
  }
};

namespace phc {
long long modpow(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}
long long modinv(long long a) {
  long long b = MOD, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= MOD;
  if (u < 0) u += MOD;
  return u;
}
long long gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
}  // namespace phc

template <int mod>
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt<MOD>;

constexpr int dy[4] = {-1, 0, 1, 0}, dx[4] = {0, -1, 0, 1};

int main() {
  int N;
  io.read(N);
  using ld = long double;
  vector<ld> dp(N + 1);
  dp[2] = 1;
  vector<vector<ld>> com(101, vector<ld>(101));
  com[0][0] = 1;
  for (int i = 1; i < 101; ++i) {
    com[i][0] = 1;
    for (int j = 1; j < 101; j++) {
      com[i][j] = (com[i - 1][j - 1] + com[i - 1][j]);
    }
  }
  FOR(i, 3, N + 1) {
    ld t = 0, a = 0, b = 0;
    REP(r, i + 1) {
      REP(s, i + 1 - r) {
        int p = i - r - s;
        vector<int> arr;
        if (r > 0) arr.push_back(r);
        if (s > 0) arr.push_back(s);
        if (p > 0) arr.push_back(p);
        sort(ALL(arr));
        if (arr.size() == 1) {
          b += com[i][r] * com[i - r][s];
        } else if (arr[0] < arr[1]) {
          t += com[i][r] * com[i - r][s];
          a += com[i][r] * com[i - r][s];
        } else if (arr[0] == arr[1] && arr[1] < arr[2]) {
          t += (1 + dp[arr[0]]) * com[i][r] * com[i - r][s];
          a += com[i][r] * com[i - r][s];
        } else {
          b += com[i][r] * com[i - r][s];
        }
        // debug(r, s, p, a, b);
      }
    }
    t /= a;
    t *= (a + b) / a;
    dp[i] = t;
    // debug(dp[i]);
  }
  printf("%.10Lf\n", dp[N]);
  return 0;
}

Submission Info

Submission Time
Task C - ゲーマーじゃんけん
User phocom
Language C++ (GCC 9.2.1)
Score 0
Code Size 9783 Byte
Status
Exec Time 31 ms
Memory 3960 KB

Compile Error

./Main.cpp: In member function ‘std::vector<std::pair<long long int, int> > Prime::prime_factor(long long int)’:
./Main.cpp:193:19: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  193 |         if (p + 1 < primes.size()) {
      |             ~~~~~~^~~~~~~~~~~~~~~
./Main.cpp: In member function ‘void UnionFind::make_groups()’:
./Main.cpp:264:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  264 |     for (int i = 0; i < data.size(); ++i) mp[root(i)].push_back(i);
      |                     ~~^~~~~~~~~~~~~

Judge Result

Set Name Score / Max Score Test Cases
All 0 / 100 input-002.txt, input-003.txt, input-004.txt, input-005.txt, input-006.txt, input-007.txt, input-008.txt, input-009.txt, input-010.txt, input-011.txt, input-012.txt, input-013.txt, input-014.txt, input-015.txt, input-016.txt, input-017.txt, input-018.txt, input-019.txt, input-020.txt, input-021.txt, input-022.txt, input-023.txt, input-024.txt, input-025.txt, input-026.txt, input-027.txt, input-028.txt, input-029.txt, input-030.txt, input-031.txt, input-032.txt, input-033.txt, input-034.txt, input-035.txt, input-036.txt, input-037.txt, input-038.txt, input-039.txt, input-040.txt, input-041.txt, input-042.txt, input-043.txt, input-044.txt, input-045.txt, input-046.txt, input-047.txt, input-048.txt, input-049.txt, input-050.txt, input-051.txt, input-052.txt, input-053.txt, input-054.txt, input-055.txt, input-056.txt, input-057.txt, input-058.txt, input-059.txt, input-060.txt, input-061.txt, input-062.txt, input-063.txt, input-064.txt, input-065.txt, input-066.txt, input-067.txt, input-068.txt, input-069.txt, input-070.txt, input-071.txt, input-072.txt, input-073.txt, input-074.txt, input-075.txt, input-076.txt, input-077.txt, input-078.txt, input-079.txt, input-080.txt, input-081.txt, input-082.txt, input-083.txt, input-084.txt, input-085.txt, input-086.txt, input-087.txt, input-088.txt, input-089.txt, input-090.txt, input-091.txt, input-092.txt, input-093.txt, input-094.txt, input-095.txt, input-096.txt, input-097.txt, input-098.txt, input-099.txt, input-100.txt
Case Name Status Exec Time Memory
input-002.txt 8 ms 3844 KB
input-003.txt 2 ms 3800 KB
input-004.txt 3 ms 3840 KB
input-005.txt 2 ms 3692 KB
input-006.txt 2 ms 3796 KB
input-007.txt 2 ms 3832 KB
input-008.txt 2 ms 3788 KB
input-009.txt 2 ms 3696 KB
input-010.txt 3 ms 3792 KB
input-011.txt 3 ms 3772 KB
input-012.txt 9 ms 3788 KB
input-013.txt 4 ms 3792 KB
input-014.txt 3 ms 3932 KB
input-015.txt 2 ms 3848 KB
input-016.txt 4 ms 3892 KB
input-017.txt 2 ms 3828 KB
input-018.txt 2 ms 3960 KB
input-019.txt 2 ms 3904 KB
input-020.txt 3 ms 3840 KB
input-021.txt 3 ms 3960 KB
input-022.txt 3 ms 3832 KB
input-023.txt 3 ms 3776 KB
input-024.txt 3 ms 3752 KB
input-025.txt 3 ms 3748 KB
input-026.txt 4 ms 3796 KB
input-027.txt 6 ms 3788 KB
input-028.txt 4 ms 3748 KB
input-029.txt 3 ms 3960 KB
input-030.txt 4 ms 3748 KB
input-031.txt 2 ms 3772 KB
input-032.txt 3 ms 3792 KB
input-033.txt 5 ms 3840 KB
input-034.txt 11 ms 3772 KB
input-035.txt 5 ms 3900 KB
input-036.txt 5 ms 3828 KB
input-037.txt 4 ms 3828 KB
input-038.txt 5 ms 3796 KB
input-039.txt 5 ms 3932 KB
input-040.txt 5 ms 3904 KB
input-041.txt 5 ms 3904 KB
input-042.txt 6 ms 3848 KB
input-043.txt 3 ms 3852 KB
input-044.txt 3 ms 3896 KB
input-045.txt 17 ms 3788 KB
input-046.txt 8 ms 3844 KB
input-047.txt 7 ms 3776 KB
input-048.txt 8 ms 3800 KB
input-049.txt 10 ms 3700 KB
input-050.txt 9 ms 3700 KB
input-051.txt 10 ms 3960 KB
input-052.txt 7 ms 3812 KB
input-053.txt 7 ms 3848 KB
input-054.txt 9 ms 3784 KB
input-055.txt 10 ms 3956 KB
input-056.txt 10 ms 3792 KB
input-057.txt 9 ms 3696 KB
input-058.txt 9 ms 3916 KB
input-059.txt 14 ms 3836 KB
input-060.txt 10 ms 3844 KB
input-061.txt 10 ms 3788 KB
input-062.txt 14 ms 3960 KB
input-063.txt 16 ms 3844 KB
input-064.txt 18 ms 3796 KB
input-065.txt 13 ms 3932 KB
input-066.txt 16 ms 3844 KB
input-067.txt 15 ms 3896 KB
input-068.txt 14 ms 3928 KB
input-069.txt 20 ms 3704 KB
input-070.txt 12 ms 3896 KB
input-071.txt 20 ms 3800 KB
input-072.txt 17 ms 3696 KB
input-073.txt 14 ms 3836 KB
input-074.txt 13 ms 3844 KB
input-075.txt 17 ms 3796 KB
input-076.txt 14 ms 3956 KB
input-077.txt 17 ms 3796 KB
input-078.txt 21 ms 3832 KB
input-079.txt 21 ms 3796 KB
input-080.txt 13 ms 3960 KB
input-081.txt 20 ms 3776 KB
input-082.txt 21 ms 3748 KB
input-083.txt 22 ms 3844 KB
input-084.txt 17 ms 3792 KB
input-085.txt 21 ms 3848 KB
input-086.txt 24 ms 3696 KB
input-087.txt 22 ms 3832 KB
input-088.txt 23 ms 3840 KB
input-089.txt 28 ms 3904 KB
input-090.txt 27 ms 3892 KB
input-091.txt 23 ms 3932 KB
input-092.txt 20 ms 3796 KB
input-093.txt 27 ms 3928 KB
input-094.txt 30 ms 3704 KB
input-095.txt 28 ms 3696 KB
input-096.txt 28 ms 3796 KB
input-097.txt 29 ms 3792 KB
input-098.txt 27 ms 3904 KB
input-099.txt 28 ms 3788 KB
input-100.txt 31 ms 3788 KB