QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#369521#3976. Delivery DelaysatgcWA 3ms9132kbC++142.2kb2024-03-28 13:35:292024-03-28 13:35:30

Judging History

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

  • [2024-03-28 13:35:30]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:9132kb
  • [2024-03-28 13:35:29]
  • 提交

answer

#include<bits/stdc++.h>
#define pii pair<int,int>
#define int long long

using namespace std;
const int maxn = 2010;
int n,m;
int k;

struct{int nxt,v,w;}edge[maxn*20];
int head[maxn],ec;
void add(int u,int v,int w){edge[++ec]={head[u],v,w};head[u]=ec;}
void adds(int u,int v,int w){add(u,v,w),add(v,u,w);}

int dis[maxn][maxn];

void dijkstra(int s,int(&dis)[maxn]) {
	memset(dis,0x3f,sizeof dis);
	static bool vis[maxn];
	static priority_queue<pii,vector<pii>,greater<pii>>pq;
	pq.push({dis[s]=0,s});memset(vis,0,sizeof vis);
	while(!pq.empty()) {
		int u=pq.top().second;pq.pop();
		if(vis[u])continue;vis[u]=1;
		for(int i=head[u];i;i=edge[i].nxt){
			int v=edge[i].v,w=edge[i].w;
			if(dis[v]>dis[u]+w)pq.push({dis[v]=dis[u]+w,v});
		}
	}
}

struct {
	int s,u,t;
}t[maxn];

// template<class...a>
// void deb(a... b){(cout<<...<<(cout<<b,' '))<<'\n';}

int dp[maxn];

bool chk(int h) {
	memset(dp,0x3f,sizeof dp);
	dp[0]=0;
	// infun(h);
	for(int pos=0;pos <= k;++pos) {
		if(dp[pos] > t[pos].s + h)return 0;
		// infun(pos,dp[pos],t[pos].u);
		int curtime = dp[pos]+dis[t[pos].u][1], curmax = 0, ppt = curtime;
		// deb(ppt);
		int ee=1;
		swap(ee,t[pos].u);
		// if(curtime )
		for(int i=pos+1;i<=k;++i) {
			// deb(i,curtime,curmax);
			int nxtime = max(t[i].t,curtime+max(0ll,t[i].t-max(t[i-1].t,ppt)))+dis[t[i-1].u][t[i].u];
			int nxtmax = max(curmax+max(0ll,t[i].t-max(t[i-1].t,ppt)),nxtime-t[i].s);
			if(nxtmax > h) break;
			// {
			// 	curtime = max(curtime + dis[t[i-1].u][1], t[i].t) + dis[1][t[i].u];
			// 	curmax = max(curmax, curtime - t[i].s);
			// } else 
			tie(curtime,curmax)={nxtime,nxtmax};

			// deb(curtime,curmax);
			if(curmax > h) break;
			dp[i]=min(dp[i],curtime);
		}
		swap(ee,t[pos].u);
		// deb(dp[4]);
	}
	// deb(dp[k]);
	return dp[k]<=t[k].s+h;
}

signed main() {
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>n>>m;
	for(int i=1,u,v,w;i<=m;++i)cin>>u>>v>>w,adds(u,v,w);

	for(int i=1;i<=n;++i)dijkstra(i,dis[i]);

	cin>>k;
	t[0].u=1;
	for(int i=1;i<=k;++i)cin>>t[i].s>>t[i].u>>t[i].t;
	int l = 0,r = LLONG_MAX;
	while(l < r){
		int mid = (l+r)>>1;
		if(chk(mid))r=mid;
		else l=mid+1;
	}cout<<r;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3660kb

input:

4 4
1 2 2
2 3 4
3 4 1
4 1 2
3
1 4 2
3 3 3
4 3 6

output:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 1ms
memory: 5768kb

input:

3 2
1 2 1
3 2 2
4
0 3 1
1 3 3
2 2 4
4 3 6

output:

8

result:

ok single line: '8'

Test #3:

score: 0
Accepted
time: 3ms
memory: 9020kb

input:

100 99
93 43 2
14 58 5
57 64 1
95 87 6
36 78 1
92 65 8
41 14 3
93 70 1
29 80 4
5 76 5
73 7 4
58 18 8
35 93 1
93 81 7
2 67 4
82 59 1
65 55 0
95 48 4
94 86 0
88 49 0
72 85 1
23 47 6
27 22 1
28 55 0
78 30 3
30 53 3
12 100 6
64 65 2
98 8 1
16 96 7
60 3 2
81 24 3
6 18 2
45 30 1
98 17 6
75 57 6
50 33 8
63...

output:

6854

result:

ok single line: '6854'

Test #4:

score: 0
Accepted
time: 2ms
memory: 6148kb

input:

100 99
57 37 4
95 89 5
11 3 7
4 5 2
46 76 5
68 32 4
66 28 7
66 74 8
63 59 7
31 61 6
72 98 7
8 95 4
98 82 6
78 24 3
30 31 2
6 47 7
93 59 4
73 45 8
64 36 6
52 92 1
70 34 1
5 15 1
85 29 5
78 14 2
56 20 8
87 75 2
18 66 6
65 64 1
1 8 1
91 100 0
79 22 2
18 23 4
21 97 6
33 48 3
77 72 5
17 88 7
78 12 2
36 9...

output:

2969

result:

ok single line: '2969'

Test #5:

score: -100
Wrong Answer
time: 3ms
memory: 9132kb

input:

100 99
18 57 3
54 65 4
94 34 8
90 42 8
61 77 6
92 14 0
84 92 7
58 50 5
56 100 0
18 5 0
60 2 2
54 39 0
30 44 1
61 32 0
9 19 1
91 57 7
10 48 0
82 43 1
1 31 8
66 98 8
93 77 7
15 81 5
61 40 2
85 55 5
22 78 1
75 53 5
20 67 6
78 86 6
30 48 4
69 75 5
61 79 4
12 61 3
97 53 5
9 63 6
86 90 1
50 65 2
64 28 8
7...

output:

382

result:

wrong answer 1st lines differ - expected: '282', found: '382'