QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#618462#7005. Rikka with ConsistencyhhdhhWA 166ms7396kbC++232.3kb2024-10-06 22:31:072024-10-06 22:31:07

Judging History

你现在查看的是最新测评结果

  • [2024-10-06 22:31:07]
  • 评测
  • 测评结果:WA
  • 用时:166ms
  • 内存:7396kb
  • [2024-10-06 22:31:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
#define rept(i, a, ne) for(int i = (a); ~i ; i=ne[i])
#define debug(x) cout<<#x<<": "<<x<<endl
#define fi first
#define sec second
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
typedef long long LL;
typedef long double  LD;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int,int>PII;
const int N=5e1+10;
bool bo[N][N][N];
LD d[N][N][N];
int a[N];
int dd[2]={1,-1};
LD pd[N][N];
LD eps=1e-10;
struct A
{
    int x,y,h;
    LD d;

    bool operator<(const A& a)const 
    {
        return d>a.d;
    }
};

void ud(priority_queue<A>&q,int x,int y,int h,LD di)
{
    if (d[x][y][h]>di)
    {
        d[x][y][h]=di;
        q.push({x,y,h,di});
    }
}
void slove()
{
    int n;
    cin>>n;

    rep(i,0,n+2)
    rep(j,0,n+2)
    rep(k,0,53)
    {
       bo[i][j][k]=0; 
       d[i][j][k]=1e9;
    }
    
    rep(i,0,n)
    cin>>a[i];

    priority_queue<A> q;

    d[0][n][0] = 0;
    q.push({0,n,0,0});      

    while (q.size())
    {
        auto [x,y,h,di] = q.top();
        q.pop();
  
        if (bo[x][y][h]) continue;
        bo[x][y][h] = 1;
        //  cout<<x<<' '<<y<<' '<<h<<' '<<di<<endl;
        if(x>0&&a[x]==h)
        ud(q,x-1,y,h,(a[x-1]==a[x])+di);
        if(x<n&&a[x+1]==h)
        ud(q,x+1,y,h,(a[x]==a[x+1])+di);

        if(y>0&&a[y]==h)
        ud(q,x,y-1,h,(a[y-1]==a[y])+di);
        if(y<n&&a[y+1]==h)
        ud(q,x,y+1,h,(a[y]==a[y+1])+di);

        rep(i,0,1)
        {
            int nh=h+dd[i];
            if(nh<=max(a[x],a[x+1])&&nh>=min(a[x],a[x+1])&&nh<=max(a[y],a[y+1])&&nh>=min(a[y],a[y+1]))
            {
                LD nd=pd[a[x]][a[x+1]]+pd[a[y]][a[y+1]];
                ud(q,x,y,nh,nd+di);
            }  
        }
    }
    cout<<d[n][0][0]<<endl;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
	cout << fixed << setprecision(10);
    int t=1;
	cin>>t;
    rep(i,0,50)
    rep(j,0,50)
    if(i!=j)
    pd[i][j]=sqrtl((i-j)*(i-j)+1)/fabs(i-j);
    
    while(t--)
    {
        slove();
    }


    return 0;
}
//#pragma GCC optimize(2)

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4024kb

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: -100
Wrong Answer
time: 166ms
memory: 7396kb

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
1215.0100671199
1951.6734665821
1213.9245379866
2017.5869647005
312.7644098498
3422.7892270310
138.6143738401
2149.9886075935
742.4138501043
47.2354965428
2511.3020333589
60.5339378890
87.7918204661
1518.2399452795
13.6251184001
1041.333...

result:

wrong answer In case 5, expected '1235.789070575067', but found '1215.010067119900', error '0.017101918756'.