This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int di[] = {1, -1, 0, 0 , 1 , 1 , -1 , -1};
const int dj[] = {0, 0, 1, -1 , 1 , -1 , 1 , -1};
typedef long long ll;
const int N = 3e3 + 3 ;
#define int long long
int n , m , arr[N] ;
int vis[N][N];
int calc(int idx , int jmp){
if(idx >= n || idx < 0)
return 1e9 ;
if(arr[idx])jmp = arr[idx];
if(vis[idx][jmp])
return 1e9 ;
vis[idx][jmp]++;
if(idx == 1)return 0 ;
int first = 1e9 , second = 1e9;
first = 1 + calc(idx + jmp , jmp);
second = 1 + calc(idx - jmp , jmp);
if(min(first , second) >= 5000)return -1 ;
return min(first , second);
}
int32_t main()
{
cin >> n >> m ;
for(int i = 0 ; i < m ; i ++){
int b , p ;
cin >> b >> p ;
arr[b] = p ;
}
cout << (arr[0] ? calc(0 , arr[0]) : -1 );
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |