#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e18
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 2e5+5
using namespace std;
int MOD = 1e9+7;
const int nax = 1e5+5;
const int nax2 = 200+5;
typedef complex<int> Point;
using cd = complex<double>;
const double PI = acos(-1);
ll m,n;
ll a[nax], b[nax], c[nax], d[nax], dp[nax], dp2[nax];
ll srch2(int j){
if(b[j] == n) return d[j];
if(j == -1) return INF;
if(dp2[j] != -1) return dp2[j];
dp2[j] = INF;
for (int i = j-1; i >= 0;--i)
{
if(c[i] <= b[j] && b[i] > b[j]){
dp2[j] = min(dp2[j], srch2(i)+d[j]);
}
}
return dp2[j];
}
ll srch(int j){
if(b[j] == n) return d[j];
if(j == m) return INF;
if(dp[j] != -1) return dp[j];
dp[j] = INF;
dp[j] = min(dp[j], srch2(j));
for (int i = j+1; i < m; ++i)
{
if(a[i] <= c[j] && b[i] > b[j]){
dp[j] = min(dp[j], srch(i)+d[j]);
}
}
return dp[j];
}
int main(){
optimise;
cin >> m >> n;
for (int i = 0; i < m; ++i)
{
cin >> a[i] >> b[i] >> c[i] >> d[i];
}
c[m] = 1;
memset(dp,-1, sizeof dp);
memset(dp2,-1, sizeof dp2);
ll cur = INF;
for (int i = 0; i < m; ++i)
{
if(a[i] == 1){
cur = min(cur,srch(i));
}
}
if(cur == INF) cout << -1 << endl;
else cout << cur << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
2 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1860 KB |
Output is correct |
4 |
Correct |
1 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1860 KB |
Output is correct |
7 |
Correct |
1 ms |
1856 KB |
Output is correct |
8 |
Correct |
1 ms |
1864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
2 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1860 KB |
Output is correct |
4 |
Correct |
1 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1860 KB |
Output is correct |
7 |
Correct |
1 ms |
1856 KB |
Output is correct |
8 |
Correct |
1 ms |
1864 KB |
Output is correct |
9 |
Correct |
1 ms |
1876 KB |
Output is correct |
10 |
Correct |
1 ms |
1876 KB |
Output is correct |
11 |
Correct |
1 ms |
1876 KB |
Output is correct |
12 |
Correct |
1 ms |
1876 KB |
Output is correct |
13 |
Correct |
1 ms |
1876 KB |
Output is correct |
14 |
Correct |
2 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
2 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1860 KB |
Output is correct |
4 |
Correct |
1 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1860 KB |
Output is correct |
7 |
Correct |
1 ms |
1856 KB |
Output is correct |
8 |
Correct |
1 ms |
1864 KB |
Output is correct |
9 |
Correct |
1 ms |
1876 KB |
Output is correct |
10 |
Correct |
1 ms |
1876 KB |
Output is correct |
11 |
Correct |
1 ms |
1876 KB |
Output is correct |
12 |
Correct |
1 ms |
1876 KB |
Output is correct |
13 |
Correct |
1 ms |
1876 KB |
Output is correct |
14 |
Correct |
2 ms |
1876 KB |
Output is correct |
15 |
Correct |
1 ms |
1876 KB |
Output is correct |
16 |
Correct |
1 ms |
1876 KB |
Output is correct |
17 |
Correct |
5 ms |
1876 KB |
Output is correct |
18 |
Correct |
4 ms |
1928 KB |
Output is correct |
19 |
Correct |
1 ms |
1876 KB |
Output is correct |
20 |
Correct |
4 ms |
1876 KB |
Output is correct |
21 |
Correct |
1 ms |
1876 KB |
Output is correct |
22 |
Correct |
2 ms |
1876 KB |
Output is correct |
23 |
Correct |
2 ms |
2004 KB |
Output is correct |
24 |
Correct |
2 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
2 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1860 KB |
Output is correct |
4 |
Correct |
1 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1860 KB |
Output is correct |
7 |
Correct |
1 ms |
1856 KB |
Output is correct |
8 |
Correct |
1 ms |
1864 KB |
Output is correct |
9 |
Correct |
1 ms |
1876 KB |
Output is correct |
10 |
Correct |
1 ms |
1876 KB |
Output is correct |
11 |
Correct |
1 ms |
1876 KB |
Output is correct |
12 |
Correct |
1 ms |
1876 KB |
Output is correct |
13 |
Correct |
1 ms |
1876 KB |
Output is correct |
14 |
Correct |
2 ms |
1876 KB |
Output is correct |
15 |
Correct |
1 ms |
1876 KB |
Output is correct |
16 |
Correct |
1 ms |
1876 KB |
Output is correct |
17 |
Correct |
5 ms |
1876 KB |
Output is correct |
18 |
Correct |
4 ms |
1928 KB |
Output is correct |
19 |
Correct |
1 ms |
1876 KB |
Output is correct |
20 |
Correct |
4 ms |
1876 KB |
Output is correct |
21 |
Correct |
1 ms |
1876 KB |
Output is correct |
22 |
Correct |
2 ms |
1876 KB |
Output is correct |
23 |
Correct |
2 ms |
2004 KB |
Output is correct |
24 |
Correct |
2 ms |
1876 KB |
Output is correct |
25 |
Correct |
303 ms |
2492 KB |
Output is correct |
26 |
Execution timed out |
1076 ms |
3540 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |