QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#414066#3788. Funny Car Racingggg100 ✓13ms4752kbC++201.8kb2024-05-18 14:49:312024-05-18 14:49:31

Judging History

This is the latest submission verdict.

  • [2024-05-18 14:49:31]
  • Judged
  • Verdict: 100
  • Time: 13ms
  • Memory: 4752kb
  • [2024-05-18 14:49:31]
  • Submitted

answer

#include <cstdio>
#include <queue>
#include <utility>
#include <vector>
using std::priority_queue;
using std::pair;
using std::vector;
using std::make_pair;
using std::greater;
using std::less;

#define rint register int
#define inf 0x3f3f3f3f
#define pa pair<int,int>
const int maxn = 305;
const int maxm = 50005;
typedef long long ll;

struct edge{
	int v,nxt,w;
	int open,close;
} e[maxm];
int n,m,s,t,head[maxn],tot,dis[maxn],Orz;
bool conf[maxn];
priority_queue <pa,vector<pa>,greater<pa> > dij;

inline int read();
void add(int u,int v,int a,int b,int t){e[++tot].close=b;e[tot].open=a;e[tot].v=v;e[tot].w=t;e[tot].nxt=head[u];head[u]=tot;}

int main(){
	while(scanf("%d %d %d %d",&n,&m,&s,&t)!=EOF){++Orz;tot=0;
		for(rint i=1;i<=n;++i)
		head[i]=0;
		for(rint i=0;i<maxm;++i)
		e[i].v=e[i].nxt=e[i].w=e[i].open=e[i].close=0;
		for(rint i=1;i<=n;++i)dis[i]=inf,conf[i]=false;
		for(rint i=1;i<=m;++i){
			int a=read(),b=read(),c=read(),d=read(),e=read();
			if(c>=e)
			add(a,b,c,d,e);
		}
		dis[s]=0;
		dij.push(make_pair(0,s));
		while(dij.size()){
			int u = dij.top().second;dij.pop();
			if(conf[u])continue;
			conf[u]=true;
			for(rint i = head[u];i;i=e[i].nxt){
				int v = e[i].v;
				int sum = e[i].close + e[i].open;
				int k = dis[u]%sum;
				int spend = 0;
				if(k + e[i].w > e[i].open)spend = sum - k + e[i].w;
				else spend = e[i].w;
				spend += dis[u];
				if(dis[v] > spend){
					dis[v] = spend;
					dij.push(make_pair(dis[v],v));
				}
			}
		}
		while(dij.size())dij.pop();
		printf("Case %d: %d\n",Orz,dis[t]);
	}
    return 0;
}

inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    return x*f;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 13ms
memory: 4752kb

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