/********************* بسم الله الرحمن الرحيم ***********************/
/******************** ٱلْحَمْدُ لِلَّٰهِ رَبِّ ٱلْعَالَمِينَ *************************/
/******************* Prophet Muhammad صلى الله عليه وسلم ************/
/*********************** وَقُل رَّبِّ زِدْنِي عِلْمًا **************************/
#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#else
#endif
#include <bits/stdc++.h>
#include "jumps.h"
using namespace std;
// #define int long long
#define endl '\n'
#define in binary_search
#define ll long long
#define ld long double
#define Hey ios::sync_with_stdio(false);
#define Welcome cin.tie(NULL), cout.tie(NULL);
#define all(v) v.begin(),v.end()
const int inf = 2e5, M = 2000;
int dp[M][M],n;
void init(int N,vector<int> h)
{
n=N;
if (n>M)
return;
for (int i=0;i<n;i++)
for (int j=0;j<n;j++)
dp[i][j]=(i!=j)*inf;
for (int i=0;i<n;i++)
{
int pre=i;
vector<int> v,v1;
for (int j=i+1;j<n;j++)
if (h[j]>h[pre])
v.push_back(j),pre=j,dp[i][j]=v.size();
pre=i;
for (int j=i-1;j>=0;j--)
if (h[j]>h[pre])
v1.push_back(j),pre=j,dp[i][j]=v1.size();
int p=0,p1=0;
while (p<v.size() and p1<v1.size())
{
if (h[v[p]]>h[v1[p1]])
dp[i][v[p]]=min(dp[i][v[p]],dp[i][v1[p1]]+1),p1++;
else
dp[i][v1[p1]]=min(dp[i][v1[p1]],dp[i][v[p]]+1),p++;
}
for (int j=0;j+1<v.size();j++)
dp[i][v[j+1]]=min(dp[i][v[j+1]],dp[i][v[j]]+1);
for (int j=0;j+1<v1.size();j++)
dp[i][v1[j+1]]=min(dp[i][v1[j+1]],dp[i][v1[j]]+1);
}
}
int minimum_jumps(int a, int b, int c, int d)
{
if (n>M)
return c-b;
int ans=inf;
for (int j=c;j<=d;j++)
for (int i=a;i<=b;i++)
ans=min(ans,dp[i][j]);
if (ans>=inf)
ans=-1;
return ans;
}
Compilation message
jumps.cpp: In function 'void init(int, std::vector<int>)':
jumps.cpp:52:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | while (p<v.size() and p1<v1.size())
| ~^~~~~~~~~
jumps.cpp:52:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | while (p<v.size() and p1<v1.size())
| ~~^~~~~~~~~~
jumps.cpp:59:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (int j=0;j+1<v.size();j++)
| ~~~^~~~~~~~~
jumps.cpp:61:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for (int j=0;j+1<v1.size();j++)
| ~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
62 ms |
1624 KB |
Output is correct |
4 |
Correct |
591 ms |
2000 KB |
Output is correct |
5 |
Correct |
496 ms |
1096 KB |
Output is correct |
6 |
Correct |
564 ms |
2000 KB |
Output is correct |
7 |
Correct |
453 ms |
1496 KB |
Output is correct |
8 |
Correct |
552 ms |
2000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
2 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
2 ms |
2392 KB |
Output is correct |
11 |
Correct |
2 ms |
2392 KB |
Output is correct |
12 |
Correct |
2 ms |
2392 KB |
Output is correct |
13 |
Correct |
2 ms |
2392 KB |
Output is correct |
14 |
Correct |
2 ms |
2392 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Incorrect |
2 ms |
2392 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
2 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
2 ms |
2392 KB |
Output is correct |
11 |
Correct |
2 ms |
2392 KB |
Output is correct |
12 |
Correct |
2 ms |
2392 KB |
Output is correct |
13 |
Correct |
2 ms |
2392 KB |
Output is correct |
14 |
Correct |
2 ms |
2392 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Incorrect |
2 ms |
2392 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Incorrect |
12 ms |
1588 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Incorrect |
127 ms |
1064 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Incorrect |
127 ms |
1064 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
62 ms |
1624 KB |
Output is correct |
4 |
Correct |
591 ms |
2000 KB |
Output is correct |
5 |
Correct |
496 ms |
1096 KB |
Output is correct |
6 |
Correct |
564 ms |
2000 KB |
Output is correct |
7 |
Correct |
453 ms |
1496 KB |
Output is correct |
8 |
Correct |
552 ms |
2000 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
2 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
2 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
2 ms |
2392 KB |
Output is correct |
19 |
Correct |
2 ms |
2392 KB |
Output is correct |
20 |
Correct |
2 ms |
2392 KB |
Output is correct |
21 |
Correct |
2 ms |
2392 KB |
Output is correct |
22 |
Correct |
2 ms |
2392 KB |
Output is correct |
23 |
Correct |
2 ms |
2644 KB |
Output is correct |
24 |
Incorrect |
2 ms |
2392 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |