Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); } template <class T1, class T2> inline void gmax(T1 &a, T2 b) { if (b > a) a = b; } template <class T1, class T2> inline void gmin(T1 &a, T2 b) { if (b < a) a = b; ...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
import java.io.*; import java.util.*; public class A { static double[][][][] dp; static int h, n; static double p; static int[] x; static int[] toRight, toLeft; public static void main(String[] args) throws IOException { // TODO Auto-generated method stub BufferedRead...
JAVA
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int M = 1000000007; const int MM = 998244353; const long double PI = acos(-1); template <typename T, typename U> static inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> static inline void amax(T &x, U y) { if (x < y) x = y; } tem...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class P596D { private static int clamp(int i, int min, int max) { return Math.min(max, Math.max(min, i)); } private final int h; private final double p; private fin...
JAVA
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int M = 2005; double dp[2][2][M][M], p0, p1; bool has[2][2][M][M]; int n, pos[M], h; double dfs(int f1, int f2, int l, int r) { if (l > r) return 0; int x = pos[l - 1] + (f1 ? h : 0), y = pos[r + 1] - (f2 ? 0 : h); double &ans = dp[f1][f2][l][r]; if (has[f1][f...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; double dp[2010][2010][2][2]; int a[2010]; pair<int, int> le[2010], ri[2010]; int ll[2010][2], rr[2010][2]; int h; double p, q; double go(int l, int r, int Li, int Ri) { if (l > r) return 0; if (dp[l][r][Li][Ri] > -1) { return dp[l][r][Li][Ri]; } int L = ll[l][Li...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; int n; double h; double p; int a[2005]; int l[2005], r[2005]; double dp[2005][2005][2][2]; double func(int i, int j, bool x, bool y) { if (i > j) return 0.0; if (dp[i][j][x][y] >= 0.0) return dp[i][j][x][y]; double ans = 0; double prev_l = a[i - 1]; double prev_r ...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> std::vector<int> getLeftFall(const std::vector<int>& x, int h) { std::vector<int> result(x.size()); result[0] = 0; for (size_t i = 1; i < x.size(); i++) { if (x[i] - x[i - 1] < h) { result[i] = result[i - 1]; } else { result[i] = i; } } return result; } std::ve...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int INF = int(1e9); vector<int> arr, fallright, fallleft; int n, H; double lprob, rprob; double memo[2010][2010][2][2]; double dp(int L, int R, int lfall, int rfall) { if (L > R) return 0.0; double &res = memo[L][R][lfall][rfall]; if (res == res) return res; i...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; double dp[2005][2005][2][2], p, q; int h, n; int data[2005]; int an_dp[2005], rev_dp[2005]; bool cmp(double a, double b) { if (fabs(a - b) <= 1e-9) return true; return false; } int an_solve(int now) { if (data[now] - data[now - 1] >= h) return now; if (an_dp[now] !=...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:64000000") using namespace std; const int MAXN = 2002; int n, m, h; int x[MAXN]; double p; double d[MAXN][MAXN][2][2]; int was[MAXN][MAXN][2][2]; int lef[MAXN], righ[MAXN]; double fun(int l, int r, int lq, int rq) { if (l > r) return 0.0; if (was[l][r][lq][rq...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int INF = (1 << 30) - 1; const int MAXN = 2010; double dp[MAXN][MAXN][2][2]; bool vis[MAXN][MAXN][2][2]; int n, h; double P; int X[MAXN], L[MAXN], R[MAXN]; double Solve(int l, int r, int f1, int f2) { if (l > r) return 0; if (vis[l][r][f1]...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { return (a ? gcd(b % a, a) : b); } long long int modPow(long long int x, long long int n, long long int MOD) { long long int res = 1; while (n > 0) { if (n % 2 == 1) { res = (res * x) % MOD; } n /=...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; template <typename T> inline T abs(T t) { return t < 0 ? -t : t; } const long long modn = 1000000007; inline long long mod(long long x) { return x % modn; } const int N = 2010; double memo[N][N][2][2], seen[N][N][2][2]; int n, h, x[N], we[N], wd[N]; double p; double solve...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 10; double dp[N][N][2][2]; int vis[N][N][2][2]; int n, h; double p; int ne[N], pre[N]; int v[N]; double solve(int L, int R, int b1 = 0, int b2 = 0) { if (L == R) return (1 - p) * min(h, (R != n - 1 ? (v[R + 1] - b2 * h) - v[R] : h)) + (p...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; int dist, N, h, v[2100], l[2100], r[2100]; double p, d[2][2][2100][2100]; bool viz[2][2][2100][2100]; double solve(int x, int y, int i, int j) { if (viz[x][y][i][j]) return d[x][y][i][j]; viz[x][y][i][j] = 1; double ret = 0; if (i > j) return ret; double a = solve...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; int n, h; double p; int lhs[2002], rhs[2002]; int pos[2002]; double DP[2002][2002][2][2]; double work(int l, int r, int le, int ri, int ls, int rs) { if (DP[l][r][le][ri] >= -1) return DP[l][r][le][ri]; double &ans = DP[l][r][le][ri]; ans = 0.0; if (l == r) { an...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 100; long long n, h; long double p; long long x[N], arr[N]; int lft[N], ryt[N]; long double memo[N][N][2][2]; long double DP(int l, int r, int a, int b) { if (l > r) return 0; long double& ret = memo[l][r][a][b]; if (ret != -1) return ret; ret = ...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int MAXN = 2005; int n, h, x[MAXN]; double p; int tail[MAXN], head[MAXN]; int rlen[MAXN], llen[MAXN]; double dp[MAXN][MAXN]; double pl[MAXN][MAXN], pr[MAXN][MAXN]; void solve() { memset(dp, 0, sizeof(dp)); memset(pl, 0, sizeof(pl)); ...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; double dp[2002][2002][1 << 2], p; int n, h, lft[2002], rht[2002]; long long x[2002]; long long min(long long x, long long y) { return x < y ? x : y; } double dfs(int l, int r, int msk) { if (l > r) return 0.0; if (dp[l][r][msk] > 0.0) return dp[l][r][msk]; double ans ...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; int n, h; double p; int v[2222]; int tol[2222], tor[2222]; double dp[2222][2222][2][2]; bool vis[2222][2222][2][2]; double dfs(int l, int r, int f1, int f2) { if (vis[l][r][f1][f2]) return dp[l][r][f1][f2]; if (l > r) return 0; int h1 = min(h, v[l] - v[l - 1] - f1 * h...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; int n, h, A[2005]; double p, dp[2][2][2005][2005]; double dfs(int x, int y, int l, int r) { double &T = dp[x][y][l][r]; if (T != -1) return T; if (l == r) { if (x == 1 && A[l] - A[l - 1] < h) return T = min(h, A[l + 1] - A[l] - (y == 0) * h); if (y == 0 ...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int N = 2000 + 10; const double inf = 1e8 + 10; double dp[N][N][2][2]; int limit[N][2]; double p; int n; double aa[N], h; double fun(int l, int r, int f1, int f2) { double le, re; double ret = 0; if (dp[l][r][f1][f2] >= 0) return dp[l][r][f1][f2]; if (l > r) r...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Scanner; public class D { public static void main(String[] args) { Scanner sc = new Scanner(new BufferedReader(new InputStreamReader( System.in))); int n = sc.nextInt(); ...
JAVA
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 100; long long n, h; long double p; long long x[N], arr[N]; int lft[N], ryt[N]; long double dp[N][N][2][2]; double compute(int lef, int rig, int fl, int fr) { if (lef > rig) return 0; if (dp[lef][rig][fl][fr] != -1) return dp[lef][rig][fl][fr]; dp[...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 2000 + 10, inf = 1e9 + 1; long long x[maxn], h; long double p, dp[maxn][maxn][2][2]; bool v[maxn][maxn][2][2]; double go(int l, int r, int dl, int dr) { if (l > r) return 0.0; if (v[l][r][dl][dr]) return dp[l][r][dl][dr]; v[l][r][dl][dr] = true; if ...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; template <class T, class U> inline void Max(T &a, U b) { if (a < b) a = b; } template <class T, class U> inline void Min(T &a, U b) { if (a > b) a = b; } inline void add(int &a, int b) { a += b; if (a >= 10000000...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int MAX_N = 2005; double dp[MAX_N][MAX_N][2][2]; int n, h; double p; int x[MAX_N], Left[MAX_N], Right[MAX_N]; const int inf = 1e9 + 10; void prepare() { for (int i = 1; i <= n; i++) if (x[i] - x[i - 1] >= h) Left[i] = i - 1; else Left[i] = Left[i...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
import java.io.IOException; import java.util.Arrays; import java.util.InputMismatchException; public class WilburAndTrees { private static final int MAX = 1000000000; public static void main(String[] args) { FasterScanner sc = new FasterScanner(); int N = sc.nextInt(); int H = s...
JAVA
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int N = 2010, INF = 1e9 + 10; int n, h; double p; int x[N], pre[N], nxt[N]; bool vis[N][N][2][2]; double f[N][N][2][2]; double dfs(int i, int j, int f1, int f2) { if (i > j) return 0; if (vis[i][j][f1][f2]) return f[i][j][f1][f2]; vis[i][j][f1][f2] = 1; int l ...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; int N, H; long double p, q; long double dp[4][2005][2005]; int pos[2005]; double solve(int msk, int l, int r) { if (l > r) { return 0; } if (dp[msk][l][r] + 1) { return dp[msk][l][r]; } int cstll, cstlr, cstrl, cstrr; dp[msk][l][r] = 0; if (msk & 1) { ...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
import java.util.*; /* */ import java.io.*; public class d { public static void main(String[] arg) { new d(); } int n, h; double p; int[] x; double[][][][] memo; int[] left; int[] right; public d() { FastScanner in = new FastScanner(System.in); PrintWriter out = new PrintWriter(System.out); n = in...
JAVA
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int N = 2222; int n, h; double dp[N][N][2][2]; int a[N]; int lf[N], rg[N]; double p; double get(int i, int j, int t1, int t2) { return (i > j ? 0.0 : dp[i][j][t1][t2]); } int main() { ios::sync_with_stdio(false); scanf("%d%d%lf", &n, &h, &p); for (int i = 1; i...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; double dp[2111][2111][2][2], P; int n, x[2111], h; int goLeft[2111], goRight[2111]; int getGoLeft(int i) { if (goLeft[i] != -1) return goLeft[i]; int &p = goLeft[i]; p = i; while (p > 1 && x[p - 1] + h > x[p]) --p; return p; } int getGoRig...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.InputStream; /** * Built using CHelper...
JAVA
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> const char en = '\n'; using namespace std; vector<long long> R(2000 + 47, 0), L(2000 + 47, 0); long long n, h; long double p; vector<long long> V; long double M[2047][2047][2][2]; long double r(long long z, long long k, bool zz, bool kk) { if (z > k) return 0; if (M[z][k][zz][kk] > -1) retu...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { return x > 0 ? x : -x; } vector<int> x; int n, h; double p; int wtf1[3000]; int wtf0[3000]; bool was[2100][2100][2][2]; double cache[2100][2100][2][2]; double solve(int l, int r, int f1, int f2) { if (was[l][r][f1][f2]) return cache[l][r]...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int N = 2020; int prv[N], nxt[N], n; long long h, x[N]; int px[N], nx[N], pxa[N], nxa[N]; bool mark[N][N][4]; double p, dp[N][N][4]; void prep() { for (int i = n - 1; i >= 0; i--) { if (i + 1 == n || x[i + 1] - x[i] >= h) { nxa[i] = h; nxt[i] = i; ...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 5; const int inf = 1e9 + 7; int read() { int s = 0; char c = getchar(), lc = '+'; while (c < '0' || '9' < c) lc = c, c = getchar(); while ('0' <= c && c <= '9') s = s * 10 + c - '0', c = getchar(); return lc == '-' ? -s : s; } void write(int x)...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const string debug_line = "yolo"; const double PI = 4 * atan(1); double dp[2010][2010][2][2]; int first[2010]; int r1[2010]; int l1[2010]; double p; int h; double tryall(int l, int r, int dl, int dr) { if (l > r) { return 0; } else if (dp...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; int p[2100]; double dp[2100][2100][2][2]; int lt[2100]; int rt[2100]; int h; int n; double t; double calc(int a, int b, int c, int d) { if (a > b) return 0; if (dp[a][b][c][d] > -0.5) { return dp[a][b][c][d]; } if (a == b) { int ld = h; int rd = h; i...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int _ = 2010; int n, h; double p; int x[_], L[_], R[_]; double f[2][_][_][2]; double dl[_][2], dr[_][2]; double dp(int bl, int l, int r, int br) { if (l > r) return 0; if (f[bl][l][r][br] > -1) return f[bl][l][r][br]; double pll = dl[l][bl] + dp(0, l + 1, r, br)...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int Scan() { int res = 0, ch, flag = 0; if ((ch = getchar()) == '-') flag = 1; else if (ch >= '0' && ch <= '9') res = ch - '0'; while ((ch = getchar()) >= '0' && ch <= '9') res = res * 10 + ch - '0'; return flag ? -res : res; } int...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const long long int maxn = 1e6 + 1; double pie = 3.1415926535; double dp[2002][2002][2][2], p; long long int h, dright[2002], dleft[2002], a[2002]; double go(long long int lidx, long long int ridx, bool s, bool d, long long int ls, long lo...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; int ll[2005], lr[2005]; double f[2005][2005][2][2]; int a[2005]; int n, h; double k; double dfs(int l, int r, int al, int ar) { if (l > r) return 0; if (f[l][r][al][ar] != 0) return f[l][r][al][ar]; double s = 0; s += k * 0.5 * (min(a[l] - a[l - 1] - al * h, h) + df...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; int reachLeft[2010], reachRight[2010], x[2010]; int reach[2010]; double dp[2010][2010][2][2]; int n, h; double p; void precalc1(int x[], int sol[]) { for (int i = 1; i <= n; ++i) { if (x[i] - h < x[i - 1]) { sol[i] = sol[i - 1]; } else sol[i] = i; } ...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; long long x[2003], h, nl[2003], nr[2003], n; double P; double f[2][2][2003][2003]; bool t[2][2][2003][2003]; void dfs(int a, int b, int l, int r) { if (l > r || t[a][b][l][r]) return; dfs(0, b, l + 1, r); if (a == 0) f[a][b][l][r] += (double)P / 2 * (min(h...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; long long x[2003], h, nl[2003], nr[2003], n; double P; double f[2][2][2003][2003]; bool t[2][2][2003][2003]; void dfs(int a, int b, int l, int r) { if (l > r || t[a][b][l][r]) return; dfs(0, b, l + 1, r); if (a == 0) f[a][b][l][r] += (double)P / 2 * (min(h...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; const long long llinf = 1e18 + 7; const double eps = 1e-15; const int N = 2010; long long x[N], h; int fl[N], fr[N]; int n; double dp[N][2][N][2]; double PFL, PFR, PCL, PCR; double f(int l, int ld, int r, int rd) { if (l > r) return 0; double &r...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; double dp[2005][2005][2][2]; int pos[2005]; int cl[2005], cr[2005]; int n; double p, h; void ini() { cl[1] = 1; for (register int i = 2; i <= n; i++) { if (pos[i] - pos[i - 1] < h) cl[i] = cl[i - 1]; else cl[i] = i; } cr[n] = n; for (register i...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
import java.io.InputStream; import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; import java.util.Arrays; /** * Built using CHelper plug-in * Actual solution ...
JAVA
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int N = 2007; int n, h; int x[N]; double p; double dp[N][N][2][2]; bool vis[N][N][2][2]; int l[N], r[N]; double DP(int L, int R, int s1, int s2) { if (L > R) return 0; double &ret = dp[L][R][s1][s2]; if (vis[L][R][s1][s2]) return ret; vis[L][R][s1][s2] = 1; ...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
import java.io.IOException; import java.util.Arrays; import java.util.InputMismatchException; public class WilburAndTrees { private static final int MAX = 1000000000; public static void main(String[] args) { FasterScanner sc = new FasterScanner(); int N = sc.nextInt(); int H = s...
JAVA
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; double f[2008][2008][2][2]; int x[2008]; int main() { int n, h, i, j; double p, ans; scanf("%d%d%lf", &n, &h, &p); for (i = 1; i <= n; i++) scanf("%d", &x[i]); x[0] = -400000000; x[n + 1] = 400000000; sort(x, x + n + 2); f[1][n][0][0] = 1.0; ans = 0.0; f...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.InputStream; /** * Built using CHelper...
JAVA
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; inline int max(int a, int b) { return a < b ? b : a; } inline int min(int a, int b) { return a > b ? b : a; } inline long long max(long long a, long long b) { return a < b ? b : a; } inline long long min(long long a, long long b) { return a > b ? b : a; } const int mod = 1e...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; long long gcd(long long b, long long s) { return (s != 0) ? gcd(s, b % s) : b; } long long Pow(long long a, long long b, long long c) { if (b == 0) return 1 % c; else if (b == 1) return a % c; else { long long A = Pow(a, b / 2, c); A = (A * A) % c; ...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, w = 0; char ch = getchar(); while (!isdigit(ch)) w |= ch == '-', ch = getchar(); while (isdigit(ch)) x = (x << 1) + (x << 3) + ch - '0', ch = getchar(); return w ? -x : x; } long long loc[2007], dl[2007], dr[2007], h, n; ...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; bool vis[2001][2001][2][2]; double f[2001][2001][2][2]; int n; double h, p; int nxt[3001], pre[3001]; double nxtlen[3001], prelen[3001]; double x[3001]; double Dp(int l, int r, int mask1, int mask2) { if (l > r) return 0.0; if (vis[l][r][mask1][mask2]) return f[l][r][ma...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int NMAX = 2005; int A[NMAX]; int leftMost[NMAX], rightMost[NMAX]; double dp[NMAX][NMAX][2][2]; int main() { ios::sync_with_stdio(false); int n, h; cin >> n >> h; long double fall; cin >> fall; for (int i = 1; i <= n; ++i) cin >> A[i]; sort(A + 1, A + n ...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
//package codeforces.cfr331div2; import java.util.Arrays; import java.util.Scanner; /** * Created by raggzy on 15-Feb-16. */ public class D { private static double get(double[][] arr, int l, int r) { int n = arr.length; if (l < 0 || l >= n || r < 0 || r >= n) return 0; return arr[l][r]; ...
JAVA
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; int x[2005]; int pos[2005][2]; long double dp[2005][2005][2][2]; bool vis[2005][2005][2][2]; int n, h; long double p; long double dfs(int s, int e, int c1, int c2) { if (vis[s][e][c1][c2]) return dp[s][e][c1][c2]; if (s > e) return 0; vis[s][e][c1][c2] = 1; long dou...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int N = 2005; const int INF = 2147483647; double p; int n, h, x[N], f[N], LEFT[N], RIGHT[N]; double dp[N][N][2][2]; int visit[N][N][2][2]; double dfs(int l, int r, int ll, int rr) { if (l > r) { return 0.0; } if (visit[l][r][ll][rr]) { return dp[l][r][ll...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
import java.io.*; import java.util.Arrays; import java.util.StringTokenizer; /** * Created by sbabkin on 9/14/2015. */ public class SolverD { public static void main(String[] args) throws IOException { new SolverD().Run(); } BufferedReader br; PrintWriter pw; StringTokenizer stok; ...
JAVA
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
import java.io.*; import java.util.*; public class D { InputStream is; int __t__ = 1; int __f__ = 0; int __FILE_DEBUG_FLAG__ = __f__; String __DEBUG_FILE_NAME__ = "src/D2"; FastScanner in; PrintWriter out; public void solve() { int n = in.nextInt(); int h = in.nextInt(); double p = in.nextDouble(); ...
JAVA
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 2100; int n, h; double p; double dp[MAXN][MAXN][2][2]; int pos[MAXN], vis[MAXN][MAXN][2][2]; double cal(int l, int r, int a, int b) { if (vis[l][r][a][b]) return dp[l][r][a][b]; vis[l][r][a][b] = 1; int left = pos[l - 1], right = pos[r + 1]; if (a) ...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; double dp[2005][2005][2][2]; int vis[2005][2005][2][2]; int n; double h, p; int v[2005]; int dl[2005], dr[2005]; double dfs(int l, int r, int xx, int yy) { if (dp[l][r][xx][yy]) return dp[l][r][xx][yy]; if (l > r) return 0; double result = 0; in...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int MAX = 2005, INF = 0x3f3f3f3f; int n, h; int p[MAX]; int doklel[MAX], dokler[MAX]; long double dp[2][2][MAX][MAX]; long double prob; long double Rek(int stl, int str, int l, int r) { if (l > r) return 0; if (dp[stl][str][l][r] > -0.5) return dp[stl][str][l][r];...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; int n, h, d[2005]; double p; double dp[2005][2005][2][2]; double fon(int a, int b, int at, int bt) { double don = 0; if (a && b < n - 1 && d[a - 1] + at * h >= d[b + 1] - ((1 - bt) * h)) return d[b + 1] - ((1 - bt) * h) - (d[a - 1] + at * h); if (a > b) return 0; ...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; int N, H; long double p, q; long double dp[4][2005][2005]; int pos[2005]; double solve(int msk, int l, int r) { if (l > r) { return 0; } if (dp[msk][l][r] + 1) { return dp[msk][l][r]; } if (msk == 1 && pos[r + 1] - H <= pos[l - 1] + H) { return 0; } ...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int N = 2010; int n, h, first[N], l[N], r[N]; double p, q, f[N][N][2][2]; bool check[N][N][2][2]; void read() { cin >> n >> h >> p; for (int i = 1; i <= n; i++) cin >> first[i]; } void init() { sort(first + 1, first + n + 1); first[0] = first[1] - h; first[n...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; int x[2005]; double dp[2005][2005][2][2]; bool vis[2005][2005][2][2]; int n; double p, h; int dl[2005], dr[2005]; double dfs(int l, int r, int f1, int f2) { if (vis[l][r][f1][f2]) return dp[l][r][f1][f2]; if (l > r) return 0; vis[l][r][f1][f2] = true; double ans = d...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; int h; double p; double dp[2005][2005][2][2]; int rhs[2005], lhs[2005], pos[2005]; double work(int l, int r, int le, int ri, int ls, int rs) { if (dp[l][r][le][ri] > -1) return dp[l][r][le][ri]; if (l == r) { return dp[l][r][le][ri] = (p)*min(h, ls) + (1 - p) * min(...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; template <typename T> using V = vector<T>; const long long mod = 1000000007; double dp[2002][2002][2][2]; bool vis[2002][2002][2][2]; V<int> lef, rig; V<long long> a; double p; long long h; double bt(int st, int en, bool d1, bool d2) { if (st > en) return 0; if (vis[st]...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long powmod(long long a, long long b) { long long res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } int n, h; double p; vector<int> pos; int cnt[2005][2]; double ...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int MAXN = 2010; int N, H; double P; int X[MAXN]; double dp[MAXN][MAXN][2][2]; int cov[MAXN][2]; double getdp(int lt, int rt, int dl, int dr) { if (lt > rt) { return 0; } double &ref...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int MN = 2000 + 10; const int ME = 1000000 + 10; const long long mod = 998244353LL; const double pi = acos(-1.0); const int Intmax = (~(1 << 31)); const int Intmin = (1 << 31); const long long LLmax = (~(1LL << 63)...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int N = 2005; int n, h; int x[N]; double p; int rhs[N]; int lhs[N]; double dp[N][N][2][2]; double solve(int s, int e, bool lft, bool rgt, int ls, int rs) { if (s > e) { return 0; return min(0, rs - ls); } if (dp[s][e][lft][rgt] >= -1.0) { return dp[s...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; double pr; int a[2002]; void qs(int q, int w) { int e = q, r = w, t = a[q + (rand() % (w - q + 1))], y; do { while (a[e] < t) e++; while (a[r] > t) r--; if (e <= r) { y = a[e]; a[e] = a[r]; a[r] = y; e++; r--; } } while (e...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return x * f; } double p; int n, h; int x[2100]; double f[2100][2100][2]...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const double EPS = 1.0 / 1000000000; const long long mod = 1000000007; double dp[2000][2000][2][2][2]; double a[2000]; double p; double h; int n; double f(int i, int j, int lft, int rght, int prev) { if (dp[i][j][lft][rght][prev] >= 0) return dp[i][j][lft][rght][prev]; ...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; int n, tree[2005], dcheck[2005][2005][2][2], tl[2005], tr[2005], h; double dn[2005][2005][2][2], p; double fun(int b, int e, int ll, int rr) { if (b > e) return 0; if (dcheck[b][e][ll][rr]) return dn[b][e][ll][rr]; dcheck[b][e][ll][rr] = 1; double resl, resr; if (...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int M = 2005; double dp[2][2][M][M], p0, p1; bool has[2][2][M][M]; int n, pos[M], h; double dfs(int f1, int f2, int l, int r) { if (l > r) return 0; int x = pos[l - 1] + (f1 ? h : 0), y = pos[r + 1] - (f2 ? 0 : h); double &res = dp[f1][f2][l][r]; if (has[f1][f...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; double p; int n, h; const int SIZE = 2000; double table[SIZE][SIZE][2][2]; bool visited[SIZE][SIZE][2][2]; int pos[SIZE]; int leftD(int i) { return i <= 0 ? 1e9 : pos[i] - pos[i - 1]; } int rightD(int i) { return i >= n - 1 ? 1e9 : pos[i + 1] - pos[i]; } double get(int a, i...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int Maxn = 2005; const int lim = 300000000; int n, h; long double p; int x[Maxn]; long double dp[Maxn][Maxn][2][2]; int L[Maxn], R[Maxn]; long double Get(int l, int r, int f1, int f2) { if (l > r) return 0.0; if (dp[l][r][f1][f2] < -0.5) { long double res = 0....
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int N = 2e3; int n, h, aa[N + 2], vis[2][N + 1][N + 1][2]; double p, dp[2][N + 1][N + 1][2]; double dfs(int s1, int lo, int hi, int s2) { if (vis[s1][lo][hi][s2]) return dp[s1][lo][hi][s2]; vis[s1][lo][hi][s2] = 1; if (lo > hi) return 0; double here = 0; int...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; enum { NO_TREE = -1, LEFT = 0, RIGHT = 1 }; const int MAX = 2e3 + 5; double memo[MAX][MAX][2][2]; bool visited[MAX][MAX][2][2]; int x[MAX], next_right[MAX], next_left[MAX]; int n, h; double p, _p; double roll(int left, int right, int dleft, int dright) { if (left > right)...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int N = 2003; double dp[N][N][2][2]; double prob[N][N][2][2]; int t[N]; int n, h; double p; int rmost[N], lmost[N]; int main() { cin >> n >> h >> p; for (int(i) = (0); i < (n); ++(i)) { cin >> t[i]; } sort(t, t + n); int w = n - 1; rmost[n - 1] = n - 1...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 2200; double dp[MAXN][MAXN][2][2]; int a[MAXN]; double p; int n, h; double DFS(int l, int r, int lt, int rt) { if (dp[l][r][lt][rt]) return dp[l][r][lt][rt]; if (l == r) { if (lt == 1 && a[l] - a[l - 1] < h) { if (rt) return dp[l][r][l...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; int h, x[2002], f[2002][2]; double p, dp[2002][2002][2][2]; int getFalls(int n, int dir) { int c = dir > 0 ? 0 : 1; if (f[n][c] != -1) return f[n][c]; if (dir * x[n + dir] < dir * (x[n] + h * dir)) { return f[n][c] = getFalls(n + dir, dir); } return f[n][c] = ...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 2100; double f[maxn][maxn][2][2]; int le[maxn]; int ri[maxn]; int a[maxn]; int h, n; double p; double dfs(int l, int r, int x, int y) { if (l > r) return 0; if (f[l][r][x][y] >= 0) return f[l][r][x][y]; double ll = min(h, a...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int N = 2002; int n, h; double p; int a[N]; double dp[N][N][2][2]; bool vis[N][N][2][2]; int nex[N], pre[N]; double solve(int l, int r, int L, int R) { if (l > r) return 0; if (vis[l][r][L][R]) return dp[l][r][L][R]; vis[l][r][L][R] = 1; double ans = 0; if (...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 5; int n; long long h, A[N], fallLeft[N], fallRight[N], costLeft[N], costRight[N]; double p, dp[N][N][2][2]; bool vis[N][N][2][2]; double calc(int x, int y, int xdir, int ydir) { if (x > y) return 0.0; if (vis[x][y][xdir][ydir] == true) return dp[x][...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; int n, h; double p; int x[2002]; int l[2002], r[2002]; double d[2][2][2002][2002] = {}, pp[2][2][2002][2002] = {}; const double EPS = 1e-23; int main() { scanf("%d%d%lf", &n, &h, &p); x[0] = -1e9, x[n + 1] = 1e9; for (int i = 1; i <= n; ++i) scanf("%d", x + i); sort...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; double f[2102][2102][2][2]; int bdl[2102][2], bdr[2102][2]; int lft[2102], rgt[2102]; int pos[2102]; int n, h; double p; double sch(int l, int r, int fl, int fr) { double ret = 0; if (f[l][r][fl][fr] > -1) return f[l][r][fl][fr]; if (l > r) return 0; double pll, plr...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 2005; int h; double p; int a[maxn]; double dp[maxn][maxn][2][2]; double DW(int l, int r, int sl, int sr) { if (dp[l][r][sl][sr]) return dp[l][r][sl][sr]; if (l == r) { if (sl && a[l - 1] + h > a[l]) { if (sr) return dp[l][r][sl][sr] = ...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long powmod(long long a, long long b) { long long res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } int n, h; double p; vector<int> trees; int coverage[2005][2]; ...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 2015; const int INF = 0x3f3f3f3f; double dp[MAXN][MAXN][2][2]; int sz[2][MAXN]; int arr[MAXN]; int n; int h; double p; double compute(int l, int r, int fl, int fr) { if (r < l) return 0; if (dp[l][r][fl][fr] != -1) return dp[l][r][fl][fr]; dp[l][r][fl...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { return (a ? gcd(b % a, a) : b); } long long int modPow(long long int x, long long int n, long long int MOD) { long long int res = 1; while (n > 0) { if (n % 2 == 1) { res = (res * x) % MOD; } n /=...
CPP
596_D. Wilbur and Trees
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are n trees located at various positions on a line. Tree i is located at position xi. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height h....
2
10
#include <bits/stdc++.h> using namespace std; double dp[2100][2100][2][2]; int n, h; double p; int Coordinate_X[2100]; int Influence[2100][2]; void Initalize() { for (int i = 0; i <= 2010; i++) for (int j = 0; j <= 2010; j++) for (int k = 0; k <= 1; k++) for (int l = 0; l <= 1; l++) dp[i][j][k][l] =...
CPP