#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 );
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |