# Include <cstdio> # include <cstring> # include <algorithm> using namespace STD; // high-precision note-0.000000 // note for disordered input struct matrix {int N, m; double mat [2] [2]; void clear (void) {memset (MAT, 0, sizeof (MAT);} void get_e (void) {int I = 0; clear (); for (I = 0; I <n; I ++) mat [I] [I] = 1;} matrix () {clear () ;}matrix (int x, int y): n (x), m (y) {clear ();}}; matrix Operator * (const Matrix & A, const Matrix & B) {int I, j, k; matrix RET (. n, B. m); For (k = 0; k <. m; k + +) For (I = 0; I <A. N; I ++) if (A. Mat [I] [k]! = 0) for (j = 0; j <B. m; j ++) ret. mat [I] [J] + =. mat [I] [k] * B. mat [k] [J]; return ret;} matrix MYPOW (matrix A, int X) {matrix RET (. n,. m); If (x <0) return ret; ret. get_e (); While (x) {If (X & 1) ret = RET * A; A = A * A; X >>=1;} return ret ;} const int LMT = 12; int POS [LMT]; int main (void) {int N; Double P, ans; matrix TEM (2, 1), use (2, 2); While (~ Scanf ("% d % lf", & N, & P) {for (INT I = 1; I <= N; ++ I) scanf ("% d ", & amp; POS [I]); sort (Pos, POS + n + 1); TEM. clear (); TEM. mat [1] [0] = 1.0; use. mat [1] [1] = P; use. mat [1] [0] = 1-P; use. mat [0] [1] = 1; for (INT I = 1; I <= N; I ++) {ans = (MYPOW (use, pos [I]-pos [I-1]-2) * TEM ). mat [1] [0]; ans * = (1-p); TEM. clear (); TEM. mat [1] [0] = ans;} If (ANS <0) ans = 0; printf ("%. 7f \ n ", ANS);} return 0 ;}
Incorrect at first, TLE