wojiaocbj

router

Mar 28th, 2022
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. /*
  2.  Author: 曹北健(37509)
  3.  Result: AC Submission_id: 4245103
  4.  Created at: Tue Mar 29 2022 11:53:29 GMT+0800 (China Standard Time)
  5.  Problem: 5449  Time: 6 Memory: 1688
  6. */
  7.  
  8. #include <stdio.h>
  9. int main(){
  10.     int map[128] = { 0 }, n, cur = 0, i, flag = 1, maxvis = 0, step = 0;
  11.     char vis[128] = { 0 };
  12.     scanf("%d", &n);
  13.     for(i = 0; i < n; i++){
  14.         scanf("%d", map + i);
  15.     }
  16.     while(cur != n - 1){   
  17.         if(cur < 0 || cur >= n || vis[cur]){
  18.             flag = 0;
  19.             break;
  20.         }
  21.         vis[cur] = 1;
  22.         if(cur > maxvis){
  23.             maxvis = cur;
  24.         }
  25.         cur += map[cur];
  26.         step++;
  27.     }
  28.     if(flag){
  29.         printf("True\n%d\n", step);
  30.     }
  31.     else{
  32.         printf("False\n%d\n", maxvis);
  33.     }
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment