QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#402051#4363. Branch Assignment321625WA 20ms5704kbC++142.3kb2024-04-29 20:03:292024-04-29 20:03:30

Judging History

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

  • [2024-04-29 20:03:30]
  • 评测
  • 测评结果:WA
  • 用时:20ms
  • 内存:5704kb
  • [2024-04-29 20:03:29]
  • 提交

answer

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
const int N=5007;
typedef long long ll;
struct pii{int v,w;};bool vis[N];
bool operator<(pii x,pii y){return x.w>y.w;}
void dijkstra(int*dis,int s,std::vector<pii>*to)
{
	memset(dis,0x3f,N<<2);memset(vis,0,N);
	std::priority_queue<pii> pq;pq.push({s,dis[s]=0});
	while(!pq.empty())
	{
	    int i=pq.top().v;pq.pop();
	    if(vis[i])continue;vis[i]=1;
	    for(pii r:to[i])if(dis[r.v]>dis[i]+r.w)
	        pq.push({r.v,dis[r.v]=dis[i]+r.w});
	}
}
int w[N],disb[N];ll sumw[N];
std::vector<pii> to[N],ff[N];
struct cii{ll v;int k;};
inline cii operator+(cii x,cii y){return {x.v+y.v,x.k+y.k};}
inline bool operator<(cii x,cii y){return x.v==y.v?x.k<y.k:x.v<y.v;}
cii f[N];cii gtvl(int l,int r){return f[l]+(cii){(sumw[r]-sumw[l])*(r-l-1),0};}
int qid[N],ql[N],qh,qe,n;
int nihung(int l,int r,int pl,int pp)
{
//	printf("l=%d r=%d pl=%d pp=%d\n",l,r,pl,pp);
	while(l<r)
	{
		int mid=(l+r)>>1;
		if(gtvl(pl,mid)<gtvl(pp,mid))l=mid+1;
		else r=mid;
	}
//	printf("l=%d\n",l);
	return l;
}
cii chk(ll md)//mink
{
//	printf("md=%lld\n",md);
	*f={0,0};qid[qh=qe=1]=0;ql[1]=1;
	for(int i=1;i<=n;++i)
	{
		if(qh<qe&&i==ql[qh+1])++qh;//printf("i=%d qid=%d\n",i,qid[qh]);
//		for(int i=qh;i<=qe;++i)printf("%d[%d,..] ",qid[i],ql[i]);puts("");
		f[i]=gtvl(qid[qh],i)+(cii){md,1};
//		printf("f[%d]=(%lld,%d)[%lld]\n",i,f[i].v,f[i].k,f[i].v-f[i].k*md);
		while(qh<qe&&!(gtvl(qid[qe],ql[qe])<gtvl(i,ql[qe])))--qe;
		if(i<n&&!(gtvl(qid[qe],n)<gtvl(i,n)))
//		{
//			printf("|%lld %lld|\n",gtvl(qid[qe-1],n).v,gtvl(i,n).v);
			qid[++qe]=i,ql[qe]=nihung(std::max(ql[qe-1],i+1),n,qid[qe-1],i);
//		}
	}
//	printf("f[n]=(%lld,%d)[%lld]\n",f[n].v,f[n].k,f[n].v-f[n].k*md);
	return f[n];
}
int main()
{
//	freopen("i.in","r",stdin);
	int nal,k,m,eu,ev,ew;scanf("%d%d%d%d",&nal,&n,&k,&m);
	for(int i=1;i<=m;++i)scanf("%d%d%d",&eu,&ev,&ew),to[eu].push_back({ev,ew}),ff[ev].push_back({eu,ew});
	dijkstra(w,n+1,to);dijkstra(disb,n+1,ff);for(int i=1;i<=n;++i)w[i]+=disb[i],sumw[i]=w[i]+sumw[i-1];//,printf("w[%d]=%d\n",i,w[i]);
	ll L=0,R=sumw[n]*(n-1);
	while(L<R)
	{
		ll mid=(L+R)>>1;
		if(chk(mid).k>k)L=mid+1;
		else R=mid;
	}
	ll z=chk(L).v-k*L;
	printf("%lld",z);
	return 0;
}

詳細信息

Test #1:

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

input:

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

output:

13

result:

ok single line: '13'

Test #2:

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

input:

5 4 2 10
5 2 1
2 5 1
3 5 5
4 5 10
1 5 1
2 3 1
3 2 5
2 4 5
2 1 1
3 4 2

output:

24

result:

ok single line: '24'

Test #3:

score: 0
Accepted
time: 0ms
memory: 4380kb

input:

5 4 3 8
1 5 15
5 1 15
2 5 2
5 2 3
3 5 1
5 3 1
4 5 2
5 4 0

output:

4

result:

ok single line: '4'

Test #4:

score: 0
Accepted
time: 0ms
memory: 4156kb

input:

2 1 1 2
1 2 5
2 1 3

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 0ms
memory: 4168kb

input:

9 4 2 11
1 2 1
2 3 2
3 4 3
4 6 4
6 8 5
8 9 6
9 7 7
7 5 8
5 8 8
7 6 9
6 1 10

output:

304

result:

ok single line: '304'

Test #6:

score: 0
Accepted
time: 8ms
memory: 4564kb

input:

5000 4999 2 9998
1 2 10000
2 1 10000
2 3 10000
3 2 10000
3 4 10000
4 3 10000
4 5 10000
5 4 10000
5 6 10000
6 5 10000
6 7 10000
7 6 10000
7 8 10000
8 7 10000
8 9 10000
9 8 10000
9 10 10000
10 9 10000
10 11 10000
11 10 10000
11 12 10000
12 11 10000
12 13 10000
13 12 10000
13 14 10000
14 13 10000
14 15...

output:

589335814500000

result:

ok single line: '589335814500000'

Test #7:

score: 0
Accepted
time: 9ms
memory: 4576kb

input:

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

output:

1224510000

result:

ok single line: '1224510000'

Test #8:

score: -100
Wrong Answer
time: 20ms
memory: 5704kb

input:

5000 4900 2000 50000
3116 1995 5417
1801 380 719
4749 13 4103
1175 493 659
596 3035 2098
628 2199 2816
711 3295 5220
4888 4316 153
1007 2136 1990
1365 1579 8062
4076 1263 7023
3114 3756 2785
3695 3175 3364
2302 3474 5739
3062 3705 9620
3815 1026 7712
3991 3582 3049
3245 2397 5834
18 1456 1619
2186 4...

output:

167531399

result:

wrong answer 1st lines differ - expected: '166040058', found: '167531399'