QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#155213 | #7118. Closing Time | zhouhuanyi# | 0 | 4ms | 29872kb | C++14 | 1.9kb | 2023-09-01 14:05:35 | 2023-09-01 14:05:35 |
Judging History
answer
#include"closing.h"
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#define N 400000
using namespace std;
const long long inf=(long long)(1e18);
struct reads
{
int num,data;
};
int n,length,rt,fa[N+1],fa2[N+1],cl[N+1];
long long tong[N+1],dis[N+1],dis2[N+1],dp[2][N+1];
bool used[N+1];
vector<reads>E[N+1];
void add(int x,int y,int z)
{
E[x].push_back((reads){y,z}),E[y].push_back((reads){x,z});
return;
}
void dfs(int x)
{
used[x]=1;
for (int i=0;i<E[x].size();++i)
if (!used[E[x][i].num])
fa[E[x][i].num]=x,dis[E[x][i].num]=dis[x]+E[x][i].data,dfs(E[x][i].num);
return;
}
void dfs2(int x)
{
used[x]=1;
for (int i=0;i<E[x].size();++i)
if (!used[E[x][i].num])
fa2[E[x][i].num]=x,dis2[E[x][i].num]=dis2[x]+E[x][i].data,dfs2(E[x][i].num);
return;
}
int max_score(int SN,int X,int Y,long long K,vector<int>U,vector<int>V,vector<int>W)
{
int op=0,x,ans=0;
long long res=0,minn=inf;
n=SN,length=0;
for (int i=0;i<n;++i) E[i].clear(),used[i]=dis[i]=dis2[i]=0;
for (int i=0;i<n;++i) add(U[i],V[i],W[i]);
dfs(X);
for (int i=0;i<n;++i) used[i]=0;
dfs2(Y);
for (int i=0;i<n;++i)
if (max(dis[i],dis2[i])<minn)
minn=max(dis[i],dis2[i]),rt=i;
for (int i=0;i<n;++i) tong[++length]=min(dis[i],dis2[i]);
sort(tong+1,tong+length+1);
for (int i=1;i<=length;++i)
{
res+=tong[i];
if (res<=K) ans=max(ans,i);
}
x=rt,cl[x]=2;
while (x!=X) x=fa[x],cl[x]=1;
x=rt;
while (x!=Y) x=fa2[x],cl[x]=1;
for (int i=0;i<=(n<<1);++i) dp[0][i]=inf;
dp[0][0]=0;
for (int i=0;i<n;++i)
{
op^=1;
for (int j=0;j<=(n<<1);++j) dp[op][j]=inf;
for (int j=(n<<1);j>=0;--j)
{
if (!cl[i]) dp[op][j]=min(dp[op][j],dp[op^1][j]);
if (cl[i]!=2&&j) dp[op][j]=min(dp[op][j],dp[op^1][j-1]+min(dis[i],dis2[i]));
if (j>=2) dp[op][j]=min(dp[op][j],dp[op^1][j-2]+max(dis[i],dis2[i]));
}
}
for (int i=0;i<=(n<<1);++i)
if (dp[op][i]<=K)
ans=max(ans,i);
return ans;
}
详细
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 200000 31011 61157 8517583098 31011 129396 964383 1655 129396 331139 1655 191487 566483 110385 191487 865248 43212 110385 542661 43212 81682 13766 81682 91774 546589 91774 124706 780638 124706 175650 118706 10421 175650 615314 10421 151953 436270 140430 151...
output:
result:
Subtask #2:
score: 0
Runtime Error
Test #4:
score: 0
Runtime Error
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 50 23 25 382806473 0 1 375710 1 2 898637 2 3 10402 3 4 536577 4 5 385023 5 6 71075 6 7 543368 7 8 301497 8 9 174394 9 10 711312 10 11 923006 11 12 675532 12 13 838667 13 14 565729 14 15 979816 15 16 862618 16 17 576015 17 18 177751 18 19 306989 19 20 881492...
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Runtime Error
Test #36:
score: 9
Accepted
time: 3ms
memory: 29872kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 4 0 1 9 0 2 2 1 2 3 2 3 3
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 6
result:
ok
Test #37:
score: 0
Accepted
time: 2ms
memory: 29648kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 4 0 1 8 0 2 2 1 2 3 2 3 100
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 5
result:
ok
Test #38:
score: 0
Accepted
time: 4ms
memory: 29348kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 8 0 4 84 0 1 1 1 2 29 2 3 29 3 4 1 4 5 20 2 6 20 3 7 1
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 9
result:
ok
Test #39:
score: -9
Runtime Error
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 18 14 15 221112 8 10 15984 3 8 2664 6 10 5328 9 10 13320 5 10 23976 1 10 13320 3 4 5328 3 7 26640 3 11 23976 4 15 23976 6 17 18648 12 17 5328 11 13 13320 0 11 7992 15 16 5328 2 16 5328 13 14 2664
output:
result:
Subtask #6:
score: 0
Skipped
Dependency #2:
0%
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Skipped
Dependency #4:
0%
Subtask #9:
score: 0
Skipped
Dependency #1:
0%