# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1082705 |
2024-09-01T09:26:51 Z |
Arp |
Train (APIO24_train) |
C++17 |
|
84 ms |
25424 KB |
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
const i64 inf = 1e18;
struct Data{
i64 cost;
int cur,node,mask;
Data(i64 _c=0LL,int _cu=0,int _no=0,int _ma=0){
cost = _c;
cur = _cu;
node = _no;
mask = _ma;
}
bool operator < (Data D) const{
if(D.cost == cost){
return D.cur <= cur;
}
return D.cost < cost;
}
};
i64 solve(int N,int M,int W,vector<int> T,
vector<int> X,vector<int> Y,vector<int> A,vector<int> B,vector<int> C,
vector<int> L,vector<int> R){
assert(W <= 10);
vector<vector<int>> adj(N);
for(int i = 0;i < M;i++){
int u = X[i];
adj[u].push_back(i);
}
for(int i = 0;i < N;i++){
sort(adj[i].begin(),adj[i].end(),[&](int i,int j){
return A[i] > A[j];
});
}
vector<vector<int>> cur(N,vector<int>((1 << W)));
vector<vector<i64>> dist(M + 1,vector<i64>(1 << W,inf));
priority_queue<Data,vector<Data>,less<Data>> pq;
pq.push(Data(0LL,-1,0,0));
while(!pq.empty()){
Data d = pq.top();
pq.pop();
int u = (d.node == 0 ? 0 : Y[d.node - 1]);
i64 cost = d.cost;
int time = d.cur;
int mask = d.mask;
if(dist[d.node][mask] != inf) continue;
dist[d.node][mask] = cost;
while(cur[u][mask] < (int) adj[u].size()){
int ind = adj[u][cur[u][mask]];
int v = Y[ind];
i64 w = C[ind];
if(time <= A[ind]){
int ma = 0;
for(int i = 0;i < W;i++){
if(L[i] > time && R[i] <= B[ind]){
// have to consider
if(R[i] < A[ind]){
// have to pay
w += T[u];
}
ma |= (1 << i);
}
}
pq.push(Data(cost + w,B[ind],ind + 1,mask | ma));
++ cur[u][mask];
}else break;
}
}
i64 ans = 1e18;
for(int i = 1;i <= M;i++){
if(Y[i - 1] != N - 1) continue;
for(int mask = 0;mask < (1 << W);mask++){
if(dist[i][mask] != inf){
i64 cur = dist[i][mask];
for(int j = 0;j < W;j++){
if((1 << j) & mask) continue;
cur += T[N - 1];
}
ans = min(ans,cur);
}
}
}
return (ans == inf ? -1 : ans);
}
Compilation message
train.cpp: In function 'i64 solve(int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:56:8: warning: unused variable 'v' [-Wunused-variable]
56 | int v = Y[ind];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
8796 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
16116 KB |
Correct. |
2 |
Correct |
78 ms |
25300 KB |
Correct. |
3 |
Correct |
0 ms |
348 KB |
Correct. |
4 |
Correct |
13 ms |
9564 KB |
Correct. |
5 |
Correct |
1 ms |
348 KB |
Correct. |
6 |
Correct |
68 ms |
15720 KB |
Correct. |
7 |
Correct |
0 ms |
348 KB |
Correct. |
8 |
Correct |
59 ms |
25392 KB |
Correct. |
9 |
Correct |
84 ms |
25424 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
16116 KB |
Correct. |
2 |
Correct |
78 ms |
25300 KB |
Correct. |
3 |
Correct |
0 ms |
348 KB |
Correct. |
4 |
Correct |
13 ms |
9564 KB |
Correct. |
5 |
Correct |
1 ms |
348 KB |
Correct. |
6 |
Correct |
68 ms |
15720 KB |
Correct. |
7 |
Correct |
0 ms |
348 KB |
Correct. |
8 |
Correct |
59 ms |
25392 KB |
Correct. |
9 |
Correct |
84 ms |
25424 KB |
Correct. |
10 |
Runtime error |
54 ms |
17548 KB |
Execution killed with signal 6 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
8796 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |