QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#709938#5458. Shortest Path Query123456zmy#WA 1386ms209052kbC++173.3kb2024-11-04 17:31:342024-11-04 17:31:34

Judging History

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

  • [2024-11-04 17:31:34]
  • 评测
  • 测评结果:WA
  • 用时:1386ms
  • 内存:209052kb
  • [2024-11-04 17:31:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int dp[1024][50011];
long long ans[50011];
int main()
{
    memset(dp,0x3f,sizeof(dp));
    memset(ans,0x3f,sizeof(ans));
    int n,m;
    scanf("%d%d",&n,&m);
    // n=50000,m=100000;
    vector<vector<pair<int,int>>>to(n+1);
    for(int i=1,u,v,w;i<=m;i++)
    {
        scanf("%d%d%d",&u,&v,&w);
        // u=(i+1)/2,v=(i+1)/2+1,w=i&1;
        to[v].emplace_back(u,w);
    }
    int q;
    scanf("%d",&q);
    // q=50000;
    // vector<long long>ans(q+1,0x3f3f3f3f);
    vector<vector<pair<pair<int,int>,int>>>query(n+1);
    for(int i=1,a,b,x;i<=q;i++)
    {
        scanf("%d%d%d",&a,&b,&x);
        // a=rand()%10000+1,b=rand()%10000+1,x=rand()%n+1;
        query[x].push_back({{a,b},i});
    }
    vector<int>mx(n+1);
    dp[1][0]=0;
    
    for(int i=2;i<=n;i++)
    {
        for(auto tmp:to[i])mx[i]=max(mx[i],mx[tmp.first]+tmp.second);
        // memset(&dp[i_][0],0x3f,sizeof(int)*(mx[i]+10));
        for(auto tmp:to[i])
        {
            int u=tmp.first,w=tmp.second;
            int i_=i&1023,u_=u&1023;
            if(w)
            {
                for(int j=0;j<=mx[u];j+=8)
                {
                    dp[i_][j+1]=min(dp[i_][j+1],dp[u_][j]);
                    dp[i_][j+2]=min(dp[i_][j+2],dp[u_][j+1]);
                    dp[i_][j+3]=min(dp[i_][j+3],dp[u_][j+2]);
                    dp[i_][j+4]=min(dp[i_][j+4],dp[u_][j+3]);
                    dp[i_][j+5]=min(dp[i_][j+5],dp[u_][j+4]);
                    dp[i_][j+6]=min(dp[i_][j+6],dp[u_][j+5]);
                    dp[i_][j+7]=min(dp[i_][j+7],dp[u_][j+6]);
                    dp[i_][j+8]=min(dp[i_][j+8],dp[u_][j+7]);
                }
            }
            else
            {
                for(int j=0;j<=mx[u];j+=8)
                {
                    dp[i_][j]=min(dp[i_][j],dp[u_][j]+1);
                    dp[i_][j+1]=min(dp[i_][j+1],dp[u_][j+1]+1);
                    dp[i_][j+2]=min(dp[i_][j+2],dp[u_][j+2]+1);
                    dp[i_][j+3]=min(dp[i_][j+3],dp[u_][j+3]+1);
                    dp[i_][j+4]=min(dp[i_][j+4],dp[u_][j+4]+1);
                    dp[i_][j+5]=min(dp[i_][j+5],dp[u_][j+5]+1);
                    dp[i_][j+6]=min(dp[i_][j+6],dp[u_][j+6]+1);
                    dp[i_][j+7]=min(dp[i_][j+7],dp[u_][j+7]+1);
                }
            }
        }
        for(auto tmp:query[i])
        {
            long long a=tmp.first.first,b=tmp.first.second,l=tmp.second;
            int i_=i&1023;
            for(int j=0;j<=mx[i];j+=8)
            { 
                ans[l]=min(ans[l],b*j+a*dp[i_][j]);
                ans[l]=min(ans[l],b*(j+1)+a*dp[i_][j+1]);
                ans[l]=min(ans[l],b*(j+2)+a*dp[i_][j+2]);
                ans[l]=min(ans[l],b*(j+3)+a*dp[i_][j+3]);
                ans[l]=min(ans[l],b*(j+4)+a*dp[i_][j+4]);
                ans[l]=min(ans[l],b*(j+5)+a*dp[i_][j+5]);
                ans[l]=min(ans[l],b*(j+6)+a*dp[i_][j+6]);
                ans[l]=min(ans[l],b*(j+7)+a*dp[i_][j+7]);
            }
        }
    }
    for(auto tmp:query[1])ans[tmp.second]=0;
    long long anss=0;
    for(int i=1;i<=q;i++)//anss^=ans[i];//
        printf("%lld\n",ans[i]);
    // printf("%d %d\n",anss,clock());
    return 0;
}
/*
4 4
1 2 0
1 3 1
2 4 0
3 4 1
3
3 5 2
3 2 4
2 3 4
*/

詳細信息

Test #1:

score: 100
Accepted
time: 7ms
memory: 204484kb

input:

4 4
1 2 0
1 3 1
2 4 0
3 4 1
3
3 5 2
3 2 4
2 3 4

output:

3
4
4

result:

ok 3 number(s): "3 4 4"

Test #2:

score: -100
Wrong Answer
time: 1386ms
memory: 209052kb

input:

50000 100000
1 2 1
2 3 0
3 4 1
4 5 0
5 6 1
6 7 0
7 8 1
8 9 1
9 10 0
10 11 1
11 12 1
12 13 1
13 14 0
14 15 0
15 16 0
16 17 0
17 18 1
18 19 1
19 20 0
20 21 1
21 22 0
22 23 0
23 24 1
24 25 1
25 26 0
26 27 1
27 28 0
28 29 0
29 30 0
30 31 0
31 32 1
32 33 0
33 34 1
34 35 1
35 36 1
36 37 1
37 38 0
38 39 0
...

output:

2374170
2947736
3303629
3606813
1241460
142323
638606
424451
284433
3373930
601625
1163932
3696304
2421832
2905288
1394292
1010585
703265
2322025
577862
777555
2840310
2612136
2608497
4123130
2324028
2424141
1304136
895512
3896781
1894617
3770016
1020682
1783908
512001
2946674
1685745
3025669
372553...

result:

wrong answer 1st numbers differ - expected: '164602050', found: '2374170'