Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author: 曹北健(37509)
- Result: AC Submission_id: 4245103
- Created at: Tue Mar 29 2022 11:53:29 GMT+0800 (China Standard Time)
- Problem: 5449 Time: 6 Memory: 1688
- */
- #include <stdio.h>
- int main(){
- int map[128] = { 0 }, n, cur = 0, i, flag = 1, maxvis = 0, step = 0;
- char vis[128] = { 0 };
- scanf("%d", &n);
- for(i = 0; i < n; i++){
- scanf("%d", map + i);
- }
- while(cur != n - 1){
- if(cur < 0 || cur >= n || vis[cur]){
- flag = 0;
- break;
- }
- vis[cur] = 1;
- if(cur > maxvis){
- maxvis = cur;
- }
- cur += map[cur];
- step++;
- }
- if(flag){
- printf("True\n%d\n", step);
- }
- else{
- printf("False\n%d\n", maxvis);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment