QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#277008 | #7005. Rikka with Consistency | ucup-team1209# | AC ✓ | 33ms | 5940kb | C++20 | 3.2kb | 2023-12-06 14:30:02 | 2023-12-06 14:30:04 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define drep(i,y,x) for (int i=(y);i>=(x);i--)
#define pii pair<int,int>
#define fir first
#define sec second
#define MP make_pair
template<typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
const double eps=1e-10;
bool chkmin(double &x,double y){return x>y+eps?x=y,1:0;}
template<typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
void file() {
#ifdef zqj
freopen("a.in","r",stdin);
#endif
}
typedef long long ll;
typedef double db;
#define sz 5555
int n;
int h[sz];
db dp[sz][sz];
bool IN(int x,int y,int z){return x>=min(y,z)&&x<=max(y,z);}
db dis(int x,int y){return sqrt((x-y)*(x-y)+(h[x]-h[y])*(h[x]-h[y]));}
db dis(db x1,db y1,db x2,db y2) {
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
void work() {
cin>>n;
rep(i,0,n) cin>>h[i];
h[n+1]=h[n];
rep(i,0,n) rep(j,0,n) dp[i][j]=1e18;
dp[0][n]=0;
priority_queue<pair<db,pii>,vector<pair<db,pii>>,greater<pair<db,pii>>>q;
q.push({0.,{0,n}});
while (!q.empty()) {
auto [x,y]=q.top().sec; auto w=q.top().fir;
q.pop();
if (dp[x][y]!=w) continue;
if (x==y) return printf("%.10lf\n",2*w),void();
if (h[y]==h[x]&&chkmin(dp[y][x],w)) q.push({w,{y,x}});
if (h[y]!=h[y+1]&&h[y+1]==h[x]) {
if (chkmin(dp[x][y+1],w)) q.push({w,{x,y+1}});
continue;
}
db yX=y;
if (h[y]!=h[y+1]) yX=1.0*(h[x]-h[y])/(h[y+1]-h[y])+y; // CHECK
for (auto xx:{x-1,x+1}) {
if (xx<0||xx>n) continue;
if (IN(h[xx],h[y],h[y+1])) {
db ww=dis(x,xx);
if (h[y]==h[y+1]) {
if (chkmin(dp[xx][y],w+ww)) q.push({w+ww,{xx,y}});
}
else {
db _yX=1.0*(h[xx]-h[y])/(h[y+1]-h[y])+y;
ww+=dis(yX,h[x],_yX,h[xx]);
if (chkmin(dp[xx][y],w+ww)) q.push({w+ww,{xx,y}});
}
}
if (h[x]==h[y]&&h[xx]!=h[x]&&IN(h[xx],h[y],h[y-1])) {
db ww=dis(x,xx);
if (h[y]==h[y-1]) {
}
else {
db _yX=-1.0*(h[xx]-h[y])/(h[y-1]-h[y])+y;
ww+=dis(yX,h[x],_yX,h[xx]);
if (chkmin(dp[xx][y-1],w+ww)) q.push({w+ww,{xx,y-1}});
}
}
{
if (h[y]==h[y+1]) continue;
for (auto yy:{y,y+1}) {
if (yy>n) continue;
if (IN(h[yy],h[x],h[xx])) {
db ww=dis(yX,h[x],yy,h[yy]);
db xX=x;
if (h[x]!=h[xx]) xX=(xx-x)*1.0*(h[yy]-h[x])/(h[xx]-h[x])+x;
ww+=dis(x,h[x],xX,h[yy]);
int _x=min(x,xx); if (h[x]==h[xx]) _x=x;
if (chkmin(dp[yy][_x],w+ww)) q.push({w+ww,{yy,_x}});
}
}
}
}
}
assert(0);
}
int main() {
file();
int T; cin>>T;
while (T--) work();
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3748kb
input:
2 4 0 1 1 2 0 4 0 2 1 3 0
output:
12.1289902045 22.3136245686
result:
ok 2 cases
Test #2:
score: 0
Accepted
time: 5ms
memory: 5916kb
input:
500 34 0 12 2 25 18 11 17 7 24 20 19 18 34 26 14 15 11 16 3 19 6 21 34 33 12 6 29 10 27 22 5 7 7 25 0 40 0 18 15 11 15 10 9 26 34 13 35 12 27 36 33 3 7 28 6 24 12 30 38 39 14 14 12 13 24 35 28 35 11 22 19 39 8 6 18 3 0 43 0 25 1 23 21 5 16 36 22 3 31 34 9 3 41 17 11 39 22 0 16 39 15 10 8 33 24 21 20...
output:
1906.0227443439 1873.2359020590 2645.0638835510 541.3343735756 1235.7890705751 1951.6734665821 1213.9245379866 2017.5869647005 312.7644098498 3422.7892270310 138.6143738401 2149.9886075935 1046.3983990275 47.2354965428 2511.3020333589 60.5339378890 87.7918204661 2535.3037067975 13.6251184001 1041.33...
result:
ok 500 cases
Test #3:
score: 0
Accepted
time: 33ms
memory: 5804kb
input:
500 43 0 6 6 1 1 1 6 1 1 5 1 5 6 5 6 1 5 5 6 6 5 5 6 1 5 6 1 6 5 5 5 6 6 6 1 1 6 6 5 1 5 6 1 0 50 0 18 39 18 28 18 18 18 28 47 28 28 48 8 8 39 48 8 39 19 47 19 19 18 48 20 28 28 18 20 20 39 48 8 8 39 48 20 20 20 8 8 18 19 8 8 8 18 8 48 0 43 0 25 29 25 44 32 32 50 50 32 29 44 25 25 25 25 32 44 29 24 ...
output:
252.2065976424 2006.4352817213 1567.0389256057 247.4145601157 2355.1321913974 2039.2389722058 585.4789742390 1706.2900658340 2455.7783261244 1429.6683040297 386.2247435139 2328.3531873156 231.7998168538 1613.9361966964 1209.0836904200 933.4911595684 1443.0473731123 2567.8362512484 1821.0363941722 27...
result:
ok 500 cases
Test #4:
score: 0
Accepted
time: 8ms
memory: 5940kb
input:
500 42 0 27 22 28 20 31 17 33 14 34 13 35 11 42 8 44 4 49 2 50 1 23 3 47 5 46 7 43 9 41 10 38 12 36 16 32 18 30 19 29 23 23 0 44 0 23 23 27 20 32 18 36 15 38 11 44 8 45 6 47 4 48 3 23 1 50 5 46 7 43 9 42 12 41 13 40 14 37 16 35 17 33 19 31 21 29 22 28 0 48 0 48 3 46 5 44 7 41 9 39 11 37 13 35 15 32 ...
output:
19134.1832142736 24340.1014771662 4598.0135761172 35163.5943454429 19719.4946797070 24330.9798185242 17290.0968115848 31672.4505810901 30612.7890458520 21650.2868919396 26014.0448811735 10391.5615138845 25028.3336779208 36818.6491796774 29255.2609754685 24770.6063188676 17962.4126290372 21344.119291...
result:
ok 500 cases