Submission #3235925


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

using ld = __float128;
typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const ld eps = 1e-12;
const ld pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  each(x,vec) is >> x;
  return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
  rep(i,vec.size()) {
    if (i) os << " ";
    os << vec[i];
  }
  return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
  rep(i,vec.size()) {
    if (i) os << endl;
    os << vec[i];
  }
  return os;
}
using Row = vector<ld>;
using Matrix = vector<Row>;
Matrix E(ll n) {
  Matrix res(n, Row(n, 0));
  rep(i, n) res[i][i] = 1;
  return res;
}
Matrix mul(const Matrix& A, const Matrix& B) {
  const ll n = A.size(), m = A[0].size(), l = B[0].size();
  assert(m == B.size());
  Matrix res(n, Row(l, 0));
  rep(i, n) rep(j, m) rep(k, l) {
    res[i][k] += A[i][j] * B[j][k];
  }
  return res;
}
Row mul(const Matrix& A, const Row& x) {
  Matrix tx(x.size());
  rep(i, x.size()) tx[i] = Row(1, x[i]);
  tx = mul(A, tx);
  Row res(x.size());
  rep(i, x.size()) res[i] = tx[i][0];
  return res;
}
Matrix power(Matrix A, ll n) {
  assert(A.size() == A[0].size());
  Matrix res = E(A.size());
  for (ll i = 1; i <= n; i <<= 1) {
    if (i & n) res = mul(res, A);
    A = mul(A, A);
  }
  return res;
}


int main() {
  long double p; cin >> p;
  ld pp = p;
  ll n; cin >> n;
  Matrix mat = power({{1-pp, pp}, {pp, 1-pp}}, n);
  ld ans = mat[0][1];
  cout << fixed << setprecision(18) << (long double)ans << endl;
}

Submission Info

Submission Time
Task C - eject
User drafear
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2284 Byte
Status AC
Exec Time 1 ms
Memory 256 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 33
Set Name Test Cases
All 00-sample-00, 00-sample-01, 10-random_small-00, 10-random_small-01, 10-random_small-02, 10-random_small-03, 10-random_small-04, 10-random_small-05, 10-random_small-06, 10-random_small-07, 10-random_small-08, 10-random_small-09, 20-random_large-00, 20-random_large-01, 20-random_large-02, 20-random_large-03, 20-random_large-04, 20-random_large-05, 20-random_large-06, 20-random_large-07, 20-random_large-08, 20-random_large-09, 30-p_zero-00, 30-p_zero-01, 30-p_zero-02, 30-p_zero-03, 30-p_zero-04, 40-p_one-00, 40-p_one-01, 40-p_one-02, 40-p_one-03, 40-p_one-04, 90-handmade-00
Case Name Status Exec Time Memory
00-sample-00 AC 1 ms 256 KB
00-sample-01 AC 1 ms 256 KB
10-random_small-00 AC 1 ms 256 KB
10-random_small-01 AC 1 ms 256 KB
10-random_small-02 AC 1 ms 256 KB
10-random_small-03 AC 1 ms 256 KB
10-random_small-04 AC 1 ms 256 KB
10-random_small-05 AC 1 ms 256 KB
10-random_small-06 AC 1 ms 256 KB
10-random_small-07 AC 1 ms 256 KB
10-random_small-08 AC 1 ms 256 KB
10-random_small-09 AC 1 ms 256 KB
20-random_large-00 AC 1 ms 256 KB
20-random_large-01 AC 1 ms 256 KB
20-random_large-02 AC 1 ms 256 KB
20-random_large-03 AC 1 ms 256 KB
20-random_large-04 AC 1 ms 256 KB
20-random_large-05 AC 1 ms 256 KB
20-random_large-06 AC 1 ms 256 KB
20-random_large-07 AC 1 ms 256 KB
20-random_large-08 AC 1 ms 256 KB
20-random_large-09 AC 1 ms 256 KB
30-p_zero-00 AC 1 ms 256 KB
30-p_zero-01 AC 1 ms 256 KB
30-p_zero-02 AC 1 ms 256 KB
30-p_zero-03 AC 1 ms 256 KB
30-p_zero-04 AC 1 ms 256 KB
40-p_one-00 AC 1 ms 256 KB
40-p_one-01 AC 1 ms 256 KB
40-p_one-02 AC 1 ms 256 KB
40-p_one-03 AC 1 ms 256 KB
40-p_one-04 AC 1 ms 256 KB
90-handmade-00 AC 1 ms 256 KB