Submission #3235896


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() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ld p; cin >> p;
  ll n; cin >> n;
  Matrix mat = power({{1-p, p}, {p, 1-p}}, n);
  ld ans = mat[0][1];
  cout << fixed << setprecision(20) << ans << endl;
}

Submission Info

Submission Time
Task C - eject
User drafear
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2291 Byte
Status CE

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:86:13: error: no match for ‘operator>>’ (operand types are ‘std::istream {aka std::basic_istream<char>}’ and ‘ld {aka __float128}’)
   ld p; cin >> p;
             ^
In file included from /usr/include/c++/5/sstream:38:0,
                 from /usr/include/c++/5/complex:45,
                 from /usr/include/c++/5/ccomplex:38,
                 from /usr/include/x86_64-linux-gnu/c++/5/bits/stdc++.h:52,
                 from ./Main.cpp:1:
/usr/include/c++/5/istream:168:7: note: candidate: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>] <near match>
       operator>>(bool& __n)
       ^
/usr/include/c++/5/istream:168:7: note:   conversion of argument 1 would be ill-formed:
./Main.cpp:86:16: error: invalid initialization of non-const reference of type ‘bool&’ from an rvalue...