QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#411707 | #6405. Barkley | xcxc82 | TL | 0ms | 0kb | C++23 | 1.8kb | 2024-05-15 18:26:54 | 2024-05-15 18:26:54 |
answer
#include<bits/stdc++.h>
#define raed read
#define int long long
using namespace std;
const int MAXN = 410,INF = 0x3f3f3f3f;
const double eps = 0.0001;
inline int read(){
int X=0; bool flag=1; char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
if(flag) return X;return ~(X-1);
}
int T,n,m,q,t,s,a[MAXN],b[MAXN],p[MAXN],dis[MAXN][MAXN];
int f[MAXN][MAXN];//上了i门课 当前在j时最多能睡多少
signed main(){
n = read(),m = raed(),q = raed(),t = raed(),s = raed();
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
dis[i][j] = INF;
}
dis[i][i] = 0;
}
for(int i=1;i<=m;i++){
int u = raed(),v = read(),w = raed();
dis[u][v] = min(f[u][v],w);
dis[v][u] = min(dis[v][u],w);
}
vector<int> v;
for(int i=1;i<=q;i++){
int A = raed(),B = raed();
p[i] = raed();
a[p[i]] = A,b[p[i]] = B;
v.push_back(p[i]);
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
for(int k=1;k<=n;k++){
dis[i][j] = min(dis[i][j],dis[i][k]+dis[k][j]);
}
}
}
memset(f,-INF,sizeof(f));
f[0][1] = 0;
for(int i=1;i<=q;i++){
for(auto j:v){
for(int k=1;k<=n;k++){
int d = dis[k][j];
if(b[k]+d>a[j]||f[i-1][k]<0) continue;
if(b[k]+dis[k][1]+dis[1][j]<=a[j]){
f[i][j] = max(f[i][j],f[i-1][k]+(a[j]-(b[k]+dis[k][1]+dis[1][j])));
}
else f[i][j] = max(f[i][j],f[i-1][k]);
}
}
}
int i;
for(i=q;i>=1;i--){
bool check = 0;
for(auto j:v){
int now = f[i][j];
if(t-b[j]-dis[j][1]>=0) now+=t-b[j]-dis[j][1];
else continue;
if(now>=s){
check = 1;
break;
}
}
if(check) break;
}
cout<<i<<endl;
}
/*
5 4 3 10 2
3 4 1
2 5 1
4 5 1
3 1 1
2 9 2
3 9 4
6 8 3
1
5 4 4 15 3
3 4 1
4 1 1
5 2 2
5 3 2
5 6 4
8 9 3
13 14 2
4 6 5
2
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
4 4 3 2 6 4 1 3 1 2 4 1 1 4 2 1 4 3