QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#412235#3788. Funny Car Racingaccept_100 ✓12ms5412kbC++172.6kb2024-05-16 10:49:542024-05-16 10:49:55

Judging History

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

  • [2024-05-16 10:49:55]
  • 评测
  • 测评结果:100
  • 用时:12ms
  • 内存:5412kb
  • [2024-05-16 10:49:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int MAXN=350;
int n,m,s,t;
vector<int>ver[MAXN];
vector<int>edge[MAXN];
vector<int>a[MAXN],b[MAXN];
bool vis[MAXN];
int d[MAXN];
int T;
struct Node
{
    int pos,dis;
    bool operator < (const Node &x) const
    {
        return x.dis<dis;
    }
};
inline int read()
{
    int tot=0;
    char c=getchar();
    while(c<'0'||c>'9')
        c=getchar();
    while(c>='0'&&c<='9')
    {
        tot=tot*10+c-'0';
        c=getchar();    
    }
    return tot;
}
inline void dijkstra()
{
    priority_queue<Node>q;
    while(q.size())q.pop();
    q.push((Node){s,0});
    d[s]=0;
    while(q.size())
    {
        Node now=q.top();
        q.pop();
        int x=now.pos,y=now.dis;
        if(vis[x])continue;
        vis[x]=1;
        for(int i=0;i<ver[x].size();i++)
        {
            int tt=ver[x][i];
            int res=y%(a[x][i]+b[x][i]);
            if(res>=a[x][i])
            {
                if(res-a[x][i]==0&&b[x][i]+edge[x][i]+y<d[tt])
                {
                    d[tt]=b[x][i]+edge[x][i]+y;
                    if(!vis[tt])q.push((Node){tt,d[tt]});
                }
                else if(res-a[x][i]>0&&b[x][i]-(res-a[x][i])+edge[x][i]+y<d[tt])
                {
                    d[tt]=b[x][i]-(res-a[x][i])+edge[x][i]+y;
                    if(!vis[tt])q.push((Node){tt,d[tt]});
                }
            }
            else
            {
                if(a[x][i]-res>=edge[x][i]&&edge[x][i]+y<d[tt])
                {
                    d[tt]=edge[x][i]+y;
                    if(!vis[tt])q.push((Node){tt,d[tt]});
                }
                else if(a[x][i]-res<edge[x][i]&&edge[x][i]+y+b[x][i]+a[x][i]-res<d[tt])
                {
                    d[tt]=edge[x][i]+y+b[x][i]+a[x][i]-res;
                    if(!vis[tt])q.push((Node){tt,d[tt]});
                }
            }
        }
    }
}
int main()
{
    while(scanf("%d%d%d%d",&n,&m,&s,&t)!=EOF)
    {
        memset(vis,0,sizeof(vis));
        memset(d,0x3f,sizeof(d));
        for(int i=1;i<=n;i++)
        {
            ver[i].clear();edge[i].clear();
            a[i].clear();b[i].clear();
        }
        for(int i=1;i<=m;i++)
        {
            int x1=read(),x2=read(),x4=read(),x5=read(),x3=read();
            if(x3>x4)continue;
            ver[x1].push_back(x2);
            edge[x1].push_back(x3);
            a[x1].push_back(x4);
            b[x1].push_back(x5);
        }
        //cout<<d[t]<<endl;
        dijkstra();
        printf("Case %d: %d\n",++T,d[t]);
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 12ms
memory: 5412kb

input:

155 9507 117 14
19 18 2 123 1
100 97 4 155 3
121 120 1 140 1
5 8 1 121 1
69 66 2 107 2
151 150 2 190 1
68 69 1 101 1
61 60 2 126 1
124 127 2 160 3
59 55 5 133 4
66 67 1 189 1
94 96 2 108 2
65 63 2 181 2
44 48 1 130 1
28 29 1 180 1
5 6 1 107 1
29 28 1 120 1
142 140 4 152 2
46 45 2 113 1
85 88 6 163 3...

output:

Case 1: 249
Case 2: 1540
Case 3: 1741
Case 4: 191
Case 5: 651
Case 6: 767
Case 7: 204
Case 8: 1016
Case 9: 582
Case 10: 248
Case 11: 323
Case 12: 322
Case 13: 1574
Case 14: 873
Case 15: 199
Case 16: 237
Case 17: 429
Case 18: 613
Case 19: 685
Case 20: 316
Case 21: 291
Case 22: 799
Case 23: 1009
Case ...

result:

ok 27 lines