QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#709804#5458. Shortest Path Query123456zmy#WA 1678ms209116kbC++172.4kb2024-11-04 16:55:322024-11-04 16:55:36

Judging History

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

  • [2024-11-04 16:55:36]
  • 评测
  • 测评结果:WA
  • 用时:1678ms
  • 内存:209116kb
  • [2024-11-04 16:55:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int main()
{
    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);
    vector<vector<int>>dp(1024,vector<int>(50011,0x3f3f3f3f));
    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&1023][0],0x3f,sizeof(int)*(mx[i]+10));
        for(auto tmp:to[i])
        {
            int u=tmp.first,w=tmp.second;
            if(w)
            {
                for(int j=0;j<=mx[u];j+=4)
                {
                    dp[i&1023][j+1]=min(dp[i&1023][j+1],dp[u&1023][j]);
                    dp[i&1023][j+2]=min(dp[i&1023][j+2],dp[u&1023][j+1]);
                    dp[i&1023][j+3]=min(dp[i&1023][j+3],dp[u&1023][j+2]);
                    dp[i&1023][j+4]=min(dp[i&1023][j+4],dp[u&1023][j+3]);
                }
            }
            else
            {
                for(int j=0;j<=mx[u];j+=4)
                {
                    dp[i&1023][j]=min(dp[i&1023][j],dp[u&1023][j]+1);
                    dp[i&1023][j+1]=min(dp[i&1023][j+1],dp[u&1023][j+1]+1);
                    dp[i&1023][j+2]=min(dp[i&1023][j+2],dp[u&1023][j+2]+1);
                    dp[i&1023][j+3]=min(dp[i&1023][j+3],dp[u&1023][j+3]+1);
                }
            }
        }
        for(auto tmp:query[i])
        {
            long long a=tmp.first.first,b=tmp.first.second,l=tmp.second;
            for(int j=0;j<=mx[i];j+=4)
            { 
                ans[l]=min(ans[l],b*j+a*dp[i&1023][j]);
                ans[l]=min(ans[l],b*(j+1)+a*dp[i&1023][j+1]);
                ans[l]=min(ans[l],b*(j+2)+a*dp[i&1023][j+2]);
                ans[l]=min(ans[l],b*(j+3)+a*dp[i&1023][j+3]);
            }
        }
    }
    for(int i=1;i<=q;i++)printf("%lld\n",ans[i]);
    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
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 204196kb

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: 1678ms
memory: 209116kb

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:

164602050
208733870
228180204
248456409
87574800
16685198
46684062
64713954
46949896
240633535
94777502
83016099
259833741
167838804
214963500
147454419
111021650
80187604
184782450
78138570
86528820
203553394
188095596
202049239
290053220
172790198
168899028
97757186
96431009
266952297
164349486
26...

result:

wrong answer 45990th numbers differ - expected: '0', found: '1061109567'