Untitled
unknown
plain_text
a year ago
857 B
1
Indexable
Never
#include<stdio.h> int main(){ // a for input // b is reachable flag ( 0 = unreachable, 1 = reachable) // first position is always reachable int a[4], b[20] = {1}, target; for(int i=0; i<4; i++){ scanf("%d", &a[i]); } // get target position scanf("%d", &target); for(int i=0; i<4; i++){ // printf("i = %d, a[i] = %d\n", i, a[i]); for( int j = (i - a[i]); j < (i + a[i] + 1); j++ ){ if( j > -1 && b[i] == 1 ){ // non-negative positions that are reachable from position i // printf("set b[%d] reachable\n", j); b[j] = 1; } } } /* for(int i=0; i<20; i++){ printf("%d ", b[i]); } */ if( b[target] == 1 ){ printf("1"); }else{ printf("0"); } }