implementation *1000

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
int n, input;
string s;
vector<int> jump;
bool vis[100005];
bool bisa = false;

void grasshopper(int x){
	if(x < 0 || x >= n){
		bisa = true;
		return;
	}
	if(vis[x]){
		bisa = false;
		return;
	}
	vis[x] = true;
	if(s[x] == '>'){
		grasshopper(x+jump[x]);
	}
	else{
		grasshopper(x-jump[x]);
	}
}

int main(){
	
	cin >> n;
	cin >> s;
	for(int i = 0; i < n; i++){
		cin >> input;
		jump.push_back(input);
	}
	grasshopper(0);
	if(bisa){
		cout << "FINITE";
	}
	else cout << "INFINITE";
}
 	 		 	 	 			 		  		 	 								


Comments

Submit
0 Comments
More Questions

702A - Maximum Increase
1656D - K-good
1426A - Floor Number
876A - Trip For Meal
1326B - Maximums
1635C - Differential Sorting
961A - Tetris
1635B - Avoid Local Maximums
20A - BerOS file system
1637A - Sorting Parts
509A - Maximum in Table
1647C - Madoka and Childish Pranks
689B - Mike and Shortcuts
379B - New Year Present
1498A - GCD Sum
1277C - As Simple as One and Two
1301A - Three Strings
460A - Vasya and Socks
1624C - Division by Two and Permutation
1288A - Deadline
1617A - Forbidden Subsequence
914A - Perfect Squares
873D - Merge Sort
1251A - Broken Keyboard
463B - Caisa and Pylons
584A - Olesya and Rodion
799A - Carrot Cakes
1569B - Chess Tournament
1047B - Cover Points
1381B - Unmerge