# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
991724 |
2024-06-02T22:39:35 Z |
yusuf12360 |
Train (APIO24_train) |
C++17 |
|
1000 ms |
34532 KB |
#include "train.h"
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define fi first
#define se second
#define TII tuple<int, int, int>
#define ts to_string
#pragma gcc optimize("O3")
using namespace std;
const ll INF=1e18;
int MAX=0;
struct node{
vi tr=vi(0);
int l, r, mid;
node *left=nullptr, *right=nullptr;
node(int l=0, int r=0) : l(l), r(r), mid(l+r>>1) {}
void extend() {
if(l==r) return;
if(!left) left=new node(l, mid);
if(!right) right=new node(mid+1, r);
}
void update(int idx, int val) {
tr.pb(val);
if(l==r) return;
extend();
if(idx<=mid) left->update(idx, val);
else right->update(idx, val);
}
void sortin() {
sort(tr.begin(), tr.end());
if(left) left->sortin();
if(right) right->sortin();
}
int get(int ql, int qr, int lm) {
if(max(l, ql)>min(r, qr)) return 0;
if(ql<=l && r<=qr) return tr.end()-lower_bound(tr.begin(), tr.end(), lm);
int from_l=0, from_r=0;
if(left) from_l=left->get(ql, qr, lm);
if(right) from_r=right->get(ql, qr, lm);
return from_l+from_r;
}
};
vector<vector<pair<int, ll>>> dist;
int this_is_not_map(int u, int ending) { // :(
pair<int, ll> ser={ending, 0};
auto it=lower_bound(dist[u].begin(), dist[u].end(), ser);
assert(it->fi==ending);
int ret=it-dist[u].begin();
return ret;
}
ll solve(int n, int m, int w,
vi t, // biaya makanan per planet (n)
vi x, vi y, // planet x ke y (m)
vi a, vi b, // waktu berangkat dri a ke b (m)
vi c, // biaya perkereta (m)
vi l, vi r) // waktu makanan yang dibutuhkan (w)
{
// compression
set<int> s; s.insert(0);
for(int p : a) s.insert(p);
for(int p : b) s.insert(p);
for(int p : l) s.insert(p);
for(int p : r) s.insert(p);
map<int, int> mp;
for(int p : s) mp[p]=MAX++;
for(int &p : a) p=mp[p];
for(int &p : b) p=mp[p];
for(int &p : l) p=mp[p];
for(int &p : r) p=mp[p];
node *root=new node(0, MAX);
for(int i=0; i<w; i++) root->update(r[i], l[i]);
root->sortin();
vector<vector<tuple<int, int, int, ll>>> adj(n);
dist.assign(n, vector<pair<int, ll>>(0));
for(int i=0; i<m; i++) {
dist[y[i]].pb({b[i], INF});
adj[x[i]].pb(make_tuple(y[i], a[i], b[i], c[i]));
}
dist[0].pb({0, 0});
for(int i=0; i<n; i++) sort(dist[i].begin(), dist[i].end());
priority_queue<tuple<ll, int, int>> pq; pq.push({0, 0, 0});
while(!pq.empty()) {
auto [cur, u, ending] = pq.top(); pq.pop();
cur=-cur;
if(dist[u][this_is_not_map(u, ending)].se!=cur) continue;
for(auto p : adj[u]) {
auto [v, st, en, rizz] = p;
if(ending>st) continue;
ll cost=rizz+1ll*t[u]*root->get(ending+1, st-1, ending+1);
int id=this_is_not_map(v, en);
if(dist[v][id].se>cur+cost) {
dist[v][id].se=cur+cost;
pq.push(make_tuple(-dist[v][id].se, v, en));
}
}
}
ll ans=INF;
for(auto p : dist[n-1]) ans=min(ans, p.se+1ll*t[n-1]*root->get(p.fi+1, MAX-1, p.fi+1));
return ans==INF ? -1ll : ans;
}
Compilation message
train.cpp:13: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
13 | #pragma gcc optimize("O3")
|
train.cpp: In constructor 'node::node(int, int)':
train.cpp:23:47: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
23 | node(int l=0, int r=0) : l(l), r(r), mid(l+r>>1) {}
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Correct. |
2 |
Correct |
1 ms |
604 KB |
Correct. |
3 |
Correct |
1 ms |
604 KB |
Correct. |
4 |
Correct |
1 ms |
604 KB |
Correct. |
5 |
Correct |
0 ms |
348 KB |
Correct. |
6 |
Correct |
0 ms |
348 KB |
Correct. |
7 |
Correct |
0 ms |
348 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
202 ms |
30092 KB |
Correct. |
2 |
Correct |
179 ms |
34532 KB |
Correct. |
3 |
Correct |
0 ms |
348 KB |
Correct. |
4 |
Correct |
8 ms |
5724 KB |
Correct. |
5 |
Correct |
0 ms |
344 KB |
Correct. |
6 |
Correct |
564 ms |
30948 KB |
Correct. |
7 |
Correct |
0 ms |
348 KB |
Correct. |
8 |
Execution timed out |
1097 ms |
26828 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
202 ms |
30092 KB |
Correct. |
2 |
Correct |
179 ms |
34532 KB |
Correct. |
3 |
Correct |
0 ms |
348 KB |
Correct. |
4 |
Correct |
8 ms |
5724 KB |
Correct. |
5 |
Correct |
0 ms |
344 KB |
Correct. |
6 |
Correct |
564 ms |
30948 KB |
Correct. |
7 |
Correct |
0 ms |
348 KB |
Correct. |
8 |
Execution timed out |
1097 ms |
26828 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Correct. |
2 |
Correct |
1 ms |
604 KB |
Correct. |
3 |
Correct |
1 ms |
604 KB |
Correct. |
4 |
Correct |
1 ms |
604 KB |
Correct. |
5 |
Correct |
0 ms |
348 KB |
Correct. |
6 |
Correct |
0 ms |
348 KB |
Correct. |
7 |
Correct |
0 ms |
348 KB |
Correct. |
8 |
Correct |
202 ms |
30092 KB |
Correct. |
9 |
Correct |
179 ms |
34532 KB |
Correct. |
10 |
Correct |
0 ms |
348 KB |
Correct. |
11 |
Correct |
8 ms |
5724 KB |
Correct. |
12 |
Correct |
0 ms |
344 KB |
Correct. |
13 |
Correct |
564 ms |
30948 KB |
Correct. |
14 |
Correct |
0 ms |
348 KB |
Correct. |
15 |
Execution timed out |
1097 ms |
26828 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |