Submission #293066

#TimeUsernameProblemLanguageResultExecution timeMemory
293066Ruba_KJakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
1 ms384 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...