#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define cbug if(DEBUG) cout
#define setp(x) cout<<fixed<<setprecision(x)
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
//template<typename T>
//using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
ostream& operator<<(ostream &out, ii x){ out<<"("<<x.F<<","<<x.S<<")"; return out; }
template<typename T> void amax(T &a, T b){ a=max(a,b); }
template<typename T> void amin(T &a, T b){ a=min(a,b); }
const ll INF = ll(1e18);
const int MOD = 998244353;
enum class OpType {
kInsert,
kRemove
};
class PointSegmentTree{
private:
int size_;
vector<unordered_set<int>> v;
void update(int p, ll val, OpType type, int k, int l, int r)
{
if(p < l || r < p) return;
if(l == r){
if (type == OpType::kInsert)
v[k].insert(val);
else
v[k].erase(val);
return;
}
int mid = (l+r)>>1;
update(p, val, type, k*2, l, mid);
update(p, val, type, k*2+1, mid+1, r);
v[k] = merge(v[k*2], v[k*2+1]);
}
unordered_set<int> query(int s, int e, int k, int l, int r)
{
if(e < l || r < s) return {}; //dummy value
if(s <= l && r <= e) return v[k];
int mid = (l+r)>>1;
unordered_set<int> lc = query(s, e, k*2, l, mid);
unordered_set<int> rc = query(s, e, k*2+1, mid+1, r);
return merge(lc, rc);
}
public:
PointSegmentTree(): v(vector<unordered_set<int>>()) {}
PointSegmentTree(int n){
for(size_=1;size_<n;) size_<<=1;
v.resize(size_*4);
}
//void reset(){}
inline unordered_set<int> merge(const unordered_set<int> &x, const unordered_set<int> &y){
unordered_set<int> res(x.begin(), x.end());
res.insert(y.begin(), y.end());
return res;
}
inline void update(int p, ll val, OpType type){
update(p, val, type, 1, 0, size_-1);
}
inline unordered_set<int> query(int l, int r){
return query(l, r, 1, 0, size_-1);
}
};
const bool DEBUG = 0;
const int MAXN = 100005;
const int LG = 21;
struct Project
{
ll t, l, r, cost;
};
istream& operator>>(istream& in, Project &p)
{
in >> p.t >> p.l >> p.r >> p.cost;
p.l--;
p.r--;
return in;
}
bool isConnected(Project p1, Project p2)
{
if (p1.t <= p2.t)
return p2.l + p2.t <= p1.r + p1.t + 1;
return p1.r - p1.t >= p2.l - p2.t - 1;
}
ll n;
int m;
vector<Project> projects;
vector<ll> dist;
void dijkstra()
{
priority_queue<ii, vector<ii>, greater<ii>> q; // (distance, node)
fill(dist.begin(), dist.end(), INF);
for (int i = 0; i < m; i++)
{
auto p = projects[i];
if (p.l != 0) continue;
dist[i] = p.cost;
q.push({dist[i], i});
}
while (!q.empty())
{
auto [cur_dist, u] = q.top();
q.pop();
if (cur_dist > dist[u]) continue;
for (int i = 0; i < m; i++)
{
if (dist[i] <= cur_dist + projects[i].cost) continue;
if (!isConnected(projects[u], projects[i])) continue;
dist[i] = cur_dist + projects[i].cost;
q.push({dist[i], i});
}
}
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("test.in", "r", stdin);
cin >> n >> m;
projects.resize(m);
dist.resize(m);
forn(i, 0, m) cin >> projects[i];
dijkstra();
ll ans = INF;
forn(i, 0, m)
{
if (projects[i].r == n - 1)
{
ans = min(ans, dist[i]);
}
}
if (ans == INF) ans = -1;
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3065 ms |
4180 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
316 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
320 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
316 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
320 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
68 ms |
680 KB |
Output is correct |
21 |
Correct |
68 ms |
688 KB |
Output is correct |
22 |
Correct |
102 ms |
596 KB |
Output is correct |
23 |
Correct |
61 ms |
596 KB |
Output is correct |
24 |
Correct |
41 ms |
828 KB |
Output is correct |
25 |
Correct |
55 ms |
724 KB |
Output is correct |
26 |
Correct |
46 ms |
724 KB |
Output is correct |
27 |
Correct |
47 ms |
724 KB |
Output is correct |
28 |
Correct |
41 ms |
724 KB |
Output is correct |
29 |
Correct |
61 ms |
724 KB |
Output is correct |
30 |
Correct |
3 ms |
724 KB |
Output is correct |
31 |
Correct |
3 ms |
640 KB |
Output is correct |
32 |
Correct |
33 ms |
932 KB |
Output is correct |
33 |
Correct |
41 ms |
840 KB |
Output is correct |
34 |
Correct |
123 ms |
692 KB |
Output is correct |
35 |
Correct |
30 ms |
852 KB |
Output is correct |
36 |
Correct |
31 ms |
876 KB |
Output is correct |
37 |
Correct |
120 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3065 ms |
4180 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |