QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#345961 | #8309. Mountain | black_moonrise# | WA | 19ms | 182160kb | C++14 | 2.0kb | 2024-03-07 18:00:05 | 2024-03-07 18:00:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
#define MP make_pair
#define PB push_back
#define ff first
#define ss second
const int maxn = 211;
double calc(int up, int l, int r) {
// (0, l) -> (1, r) intersect [0, up]
if(l >= r) swap(l, r);
if(up <= 0) return 0;
if(up <= l) return up;
if(up > r) up = r;
double ret = l;
double q1 = (r - up) * 1.0 / (r - l);
ret += (q1 + 1) * (up - l) / 2;
return ret;
}
double f[211][1024], dp[211][211][512];
int n, h[211], W, H;
int main() {
// printf("hehe %.10lf\n", calc(0, 4, 1, 2));
scanf("%d%d%d", &n, &W, &H);
for(int i=1; i<=n; i++) scanf("%d", h+i);
for(int i=0; i<=n; i++) {
for(int j=0; j<(1<<W*2); j++) {
vector<pair<int, int> > vs;
for(int k=0; k<W*2; k++) if((j >> k) & 1) {
// [i - W+ 1, i + W]
int pos = i + W - k;
if(pos >= 0 && pos <= n+1) {
vs.emplace_back(h[pos] - H, h[pos] + H);
}
// printf("pos= %d\n", pos);
}
sort(vs.begin(), vs.end());
int cur = -1e9;
for(auto v : vs) {
// max(v.ff, cur) -> v.ss
if(cur < v.ss) {
f[i][j] += calc(v.ss, h[i], h[i+1]) - calc(max(v.ff, cur), h[i], h[i+1]);
cur = v.ss;
}
}
// printf("i= %d j= %d f= %.2lf\n", i, j, f[i][j]);
}
}
for(int i=0; i<211; i++) for(int j=0; j<211; j++) for(int k=0; k<512; k++) dp[i][j][k] = -1e100;
dp[1][0][0] = 0.0;
int tot_mask = (1 << W*2-1) - 1;
for(int i=1; i<=n + W + 1; i++) {
for(int j=0; j<i; j++) {
for(int mask=0; mask<(1<<W*2-1); mask++) {
if(dp[i][j][mask] < 0) continue;
// decided: [i - W*2 + 1, i]
for(int t=0; t<1 + (i <= n); t++) {
int nmask = (mask * 2 + t) & tot_mask;
dp[i+1][j+t][nmask] = max(dp[i+1][j+t][nmask], dp[i][j][mask] + (i >= W ? f[i-W][mask*2+t] : 0));
}
// printf("i= %d j= %d mask= %d dp= %.2lf\n", i, j, mask, dp[i][j][mask]);
}
}
}
for(int j=1; j<=n; j++) {
double ans = 0;
for(int k=0; k<(1<<W*2-1); k++) {
ans = max(ans, dp[n+W+1][j][k]);
}
printf("%.10lf\n", ans);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 19ms
memory: 181968kb
input:
3 1 2 2 1 3
output:
3.5000000000 4.5000000000 5.1666666667
result:
ok 3 numbers
Test #2:
score: 0
Accepted
time: 16ms
memory: 181824kb
input:
2 3 78 55 51
output:
106.0000000000 106.0000000000
result:
ok 2 numbers
Test #3:
score: 0
Accepted
time: 4ms
memory: 182160kb
input:
36 3 61 63 83 12 81 1 58 56 13 1 82 54 16 66 43 9 92 98 34 95 37 36 10 50 45 27 74 83 94 82 48 47 62 22 10 92 49
output:
385.5000000000 763.1796875000 1028.6796875000 1294.0789379409 1559.0109444729 1721.0109444729 1820.3747125888 1823.7332589286 1825.0000000000 1825.0000000000 1825.0000000000 1825.0000000000 1825.0000000000 1825.0000000000 1825.0000000000 1825.0000000000 1825.0000000000 1825.0000000000 1825.000000000...
result:
ok 36 numbers
Test #4:
score: 0
Accepted
time: 8ms
memory: 182024kb
input:
37 2 9 51 64 99 52 2 7 33 73 4 39 1 22 41 51 97 72 71 46 11 10 37 79 97 79 70 19 58 13 43 88 38 55 54 9 31 74 62
output:
69.6346153846 138.8937062937 207.5235755748 268.6092898605 317.5915975528 363.6906461786 408.3734516084 452.2230756686 491.3926408860 527.9283551717 564.4197085551 600.4197085551 636.3680064275 672.3106151231 707.8477579803 736.8277328967 760.4206651334 782.5022440808 803.6457081330 823.9471897535 8...
result:
ok 37 numbers
Test #5:
score: -100
Wrong Answer
time: 16ms
memory: 182140kb
input:
66 4 90 54 54 42 52 31 76 14 66 59 63 85 49 15 80 54 35 39 87 34 72 28 86 24 76 12 45 34 28 60 24 6 48 35 86 65 59 87 50 7 12 25 31 81 7 29 62 37 90 75 98 49 15 100 78 36 98 80 48 36 15 28 16 35 76 50 71
output:
545.0000000000 1000.5000000000 1437.0000000000 1869.5000000000 2299.0000000000 2639.5000000000 2955.0000000000 3182.5000000000 3218.0000000000 3218.0000000000 3218.0000000000 3218.0000000000 3218.0000000000 3218.0000000000 3218.0000000000 3218.0000000000 3218.0000000000 3218.0000000000 3218.00000000...
result:
wrong answer 6th numbers differ - expected: '2665.0000000', found: '2639.5000000', error = '0.0095685'